Helm values with build time env vars

1.5k views Asked by At

I have a Helm chart and in the deployment, I want to provide some environment variable for my pods. During build time in my CI/CD setup, I have the values as env vars and I'm passing them now like this:

helm upgrade CHART_NAME helm --install --set-string webserver.env.DATABASE_URL=$DATABASE_URL

I have like more then 20 env vars, can I access them somehow in my values.yml?

webserver:
  env:
    DATABASE_URL=${DATABASE_URL}

Sadly this one doesn't work.

2

There are 2 answers

0
Mafor On BEST ANSWER

Helm does not resolve placeholders (environment variables) inside values files, but you can do it yourself in the CI/CD script, before passing the file to the helm upgrade command:

values-env.yaml:

webserver:
  env:
    DATABASE_URL=${DATABASE_URL}

CI/CD script:

eval "echo \"$(cat values-env.yaml)\"" >> values-ci.yaml
helm upgrade CHART_NAME helm --install --values values-ci.yaml

0
avinashjha On

The better approach will be to create a values-override.yaml file and store all the values that needs to be set from Jenkins in the values-override file. Use sed command to update the value-override.yaml to the jenkins env-variable. Use the override values.yaml in the Helm upgrade command.