How to deploy a new application on k8s

Domain name

  • Get a domain name: example.com and two sub domains; www.example.com to redirect to the root domain and one for staging staging.example.com
  • Open an rt and require:
    • to point the domain to the prod-comms k8s cluster
    • to get the tls certificates as secret with this format: example-com-tls in the production namespace and staging-example-com-tls in the staging namespace.

Jenkins

Create 2 jenkins jobs:

Staging

  • Create a new job.
  • The title should have this format: example.com-staging
  • Copy from another staging project this one for example: multipass.run-staging
  • Press ok
  • In the settings page of the job change the repository URL with the correct one: https://github.com/canonical-web-and-design/example.com.git
  • In the build script change the line: export staging_domain="staging.multipass.run" to export staging_domain="staging.example.com"

If the repository is private: go on the repository of the project on GitHub. On Settings -> Collaborators and Teams, add the team Bots. This will allow our bot on Jenkins to have read and write access on the repository.

Production

  • Create a new job.
  • The title should have this format: example.com-production
  • Copy from another staging project this one for example: multipass.run-production
  • Press ok
  • In the build script change the line: export production_domain="multipass.run" to export production_domain="example.com"

k8s configurations

  • On this repository you need to add the configurations for the new service.
  • Locally run the script (included in the deployement project): ./create-project example.com
  • It will generate a new yaml file under the sites folder.
  • Take a look into the configuration and make sure it is ready. If you want to make changes into the configuration here is document about the possibles properties to use.
  • If you want to add sentry you can check here
  • Open a pull request with files generated, this changes needs to be in the master branch before applying the configurations.

Release to staging

  • Once all those steps are done we need to apply the configurations for staging.
  • On this staging job go on the configuration and add those lines at the end of the build script:
deploy example.com

Add sentry to your project

  • On our instance of sentry create a new project that should be part of the team #web
  • The name should be on this format: examplecom
  • On the settings of the project get the DSN.
  • On the k8s cluster add in the secret sentry-dsn the key-value: example-com: DSN in the namespaces staging and production
  • On the deployment configurations generated previously add in the yaml file: sites/example.com.yaml the following configuration (see canonical.com example):
env:
  - name: SENTRY_DSN
    value: https://aedc7a57f0bc4d22bf7c0b6d63c3e1bb@sentry.is.canonical.com//14

To enable GitHub integration for the project on sentry you need to use the legacy Github integration view that is on our sentry’s version. You will need to access this URL: https://sentry.is.canonical.com/settings/canonical/projects/<SENTRY_PROJECT_NAME>/plugins/github/ and follow the steps.

Add the site to releases.demo.haus

Submit a PR to update releases.demo.haus with the new domain - like this one for microstack.run.

If the repo is Github private, demo.haus will not work

Set Jenkins webhook

  • You will need Payload URL and a Secret. If you don’t have them, the team shares them in the Lastpass account.
  • After you got the URL and Secret, go to the projects GitHub settings
  • Set up a new webhook
  • Fill in Payload URL and Secret from your credentials obtained in Lastpass
  • Select Content type application/json
  • Tick the “Just the push”

Check your deployed site

  • If your domain name is still not ready, you may need to add in your hosts file:
    162.213.33.207 example.com staging.example.com

  • Now check staging.example.com in a browser. You should be able to access the deployed version of the site.

Release to production

  • Eventually, we will need to apply the configurations for production.
  • On this production job go on the configuration and add those lines at the end of the build script:
deploy example.com
  • Go back to the staging job and use the link displayed in the console after deployment to build the image.
  • Your site should be live now, check deployed site at example.com

End!

  • Deploy your service with the jobs that you created!