Upgrading to Helm

Helm, the Package Manager for Kubernetes is a wonderful addition to anyone doing DevOps operations with Kubernetes.

With Helm you can:

  • Manage development and production properties
  • Validate and test configuration resources prior to deployment
  • Group deployment resources into Releases
  • Rollback failed deployments

Learn about the Helm basics in the Helm documentation.

Manage development and production properties

You can manage the values.yaml file in a way that will allow a simpler access to environment properties. For example:

  env: development

name: myMicroService
  development: "0.0.1"
  production: "0.0.2"
  development: debug
  production: info

How to choose the environment to use? When running commands, such as helm lint, helm template, helm install or helm upgrade, you can pass the env variable. By passing it the YAML parser will know which property to apply to the template:

sh """
    helm template . --set "env=$ENV"
  • $ENV refers to an environment variable set to either “development” or “production” during the lifespan of a pipeline execution.

Note that this also requires modifying the Kubernetes resource template files. For example, in the ConfigMap.template.yaml file:

log_level: {{ index .Values.global.log_level .Values.global.env | quote }}

Learn more about Go templating commands in the Sprig library.

Validate and test configuration resources prior to deployment

helm template

To generate the actual Kubernetes configuration resources based on your resource template files before executing the pipeline, use helm template.

helm lint

To test the syntax of your configuration resources in your pipeline, use helm lint:

lintResults = sh(script: "cd config/helm/${microServiceName};helm lint -f common-values.yaml || true", returnStdout:true)
if ((lintResults.contains("[ERROR]")) || (lintResults.contains("[WARNING]"))) {
   currentBuild.result = "FAILURE"
   env.shouldBuild = "false"

   slackSend (
       color: '#F01717',
       message: "*$JOB_NAME*: <$BUILD_URL|Build #$BUILD_NUMBER>, validation stage failed.\n\n${lintResults}"

Note: the file common-values.yaml refers to an exteral values.yaml-like file containing properties that are used by multiple Charts.

Rollback failed deployments

If helm install/upgrade failed, you can revert back to the previous successful release. E.g.:

helm rollback <release name> <revision number> --force --wait --timeout 180"

To get the revision number, run

helm history <release name>