Setting separate values for environment variable in HELM for DEV, PRESTAGING, STAGING and PROD

11/12/2018

I am currently using Helm charts for deployment. What I basically wanted to do is to set environment variables for different environments.

Use-case:

I am using Helm to deploy a Node JS application and based on the value of the environment variable NODE_ENV which will be set while deployment I wish to load specific config files.

Example:

  env:
    - name: NODE_ENV
      value: production
    ...

I was going through HELM charts and I am unable to join the dots as to how we can use the templates/deployment.yaml, values.yaml and a deployment.yaml to establish the same.

Note:

It is the same environment variable which will hold separate values based on the deployment environment.

Any help would be helpful.

-- Radioactive
environment-variables
kubernetes-helm

1 Answer

11/13/2018

You can use templating to set the value of the environment variable:

- name: NODE_ENV
  value: {{ .Values.env | quote }}

Your chart's values.yaml file should provide a default value:

env: production

When you actually go to deploy the chart, you can provide an additional YAML file of values (or more than one)

helm install --name my-chart ./charts/my-chart -f values.dev.yaml

And then that YAML file can provide values that override the chart's default

env: development
mysqlHost: mysql-dev.example.com
-- David Maze
Source: StackOverflow