Using Environment Variables with HELM

6/29/2020

I plan to upgrade my project to HELM.

I have many environment variables that I have defined in deployment.yaml.

Best practice is it best to define the environment variables in the values.yaml file or the templates / deployment.yaml drop?

Can you help if there is a sample application you use?

-- public_html
helmfile
kubernetes
kubernetes-helm

2 Answers

7/7/2020

Disclaimer: My answers are based on Helm 3. So let's get to it:

  • #1: No, in your values.yaml you define the static/default values. It's not the best approach to let static values in your template files (like deployment.yaml). To override the values of values.yaml The best practice is to use --set KEY=VALUE file. In this case, is totally possible to get the environment variable.
  • #2: Can you give an example? Yes, sure.

For example, I want to install Elasticsearch on my cluster using helm so I use the command:

helm install elastic/elasticsearch --version 7.8.0

But I do not want to use the default values of the chart. So I went to https://hub.helm.sh/charts/elastic/elasticsearch and https://github.com/elastic/helm-charts/blob/7.8/elasticsearch/values.yaml, saw what's possible to change, then I create the command:

helm install elastic/elasticsearch --set minimumMasterNodes=1 --set protocol=https  --version 7.8.0

But in my CD tool, the minimum master nodes are different values and since this is an environment variable I changed my command line to this:

helm install elastic/elasticsearch --set minimumMasterNodes=$MIN_MASTER_NODES --set protocol=https  --version 7.8.0

So, as a result, the command above will run with no problem in your CD tool once the MIN_MASTER_NODES environment variable is provided correctly.

-- Geraldo Andrade
Source: StackOverflow

6/29/2020

Your use of values.yaml to define environment vars is totally up to you. Is the value static? I'd have no problem leaving it in the deployment yaml. If it's a secret you should manage it either with k8s secrets or input it when you use helm install --set-value.. If the value is dynamic and is changed often or could be changed in the future that is the true use for values.yaml imo

-- Vincent Rodomista
Source: StackOverflow