Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 767
Radioactive Avatar asked Nov 12 '18 23:11

Radioactive


1 Answers

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
like image 116
David Maze Avatar answered Nov 19 '22 11:11

David Maze