Can we use template variables in helm3 values.yaml

6/18/2020

Is it possible to use templating in helm values.yaml?

Use case - values.yaml is as below -

myservice:
  name: abc
  namespace: abc
  image:
    ecr_uri: abc.dkr.ecr.us-east-2.amazonaws.com
    repo_name: abc-123
    version: 1.0.0

I want to pass these image metadata to my environment variable within values.yaml

env:
  - name: POD_CONFIG
    value: '{
      "1234": {
        "DEPLOYMENT": "xyz",
        "IMAGE": "{{ .Values.myservice.image.ecr_uri }}/{{ .Values.myservice.image.repo_name }}:{{ .Values.myservice.image.version }}",
        "REC_COUNTS_TO_POD_COUNTS": {"0": 0, "500": 1, "1000": 2, "1500": 3, "2000": 4, "2001": 5}
        }
      }'

Output - $ helm template myservice does not render actual variable values but rather returns it as a string

 - name: POD_CONFIG
   value: '{ "1234": { "DEPLOYMENT": "xyz", "IMAGE": "{{ .Values.myservice.image.ecr_uri}}/{{ .Values.myservice.image.repo_name }}:{{ .Values.myservice.image.version }}", "REC_COUNTS_TO_POD_COUNTS":
 {"0":0,"20":1, "40":2, "60":3} } }'

Is there any way to set this version for environment variables? as I will by passing the custom version with --set command from $ helm install and $ helm upgrade commands

e.g.

$ helm install myservice ./myservice --set myservice.image.version=1.0.1 -n mynamespace --debug

I am expecting this version to be reflected in my environment variables dynamically but that is not happening right now.

-- Darshan Deshmukh
kubernetes
kubernetes-helm

0 Answers