Is it possible to have conditional variables on helm charts for deployment?

5/8/2019

Is it possible to have some sort of condition check before declaring a variable in a helm chart for deployment?

For example lets say I have

        - name: EXAMPLE_VAR
          valueFrom:
            secretKeyRef:
              name: "name"
              key: "key"

but I only want to include this in my deployment for a specific configuration (based on lets say an environment variable) and don't want to have to maintain a seperate yaml configuration just for this configuration option

-- Jared
continuous-integration
kubernetes
kubernetes-helm

1 Answer

5/8/2019

Let's say you have this in your chart's values.yaml

some-condition: true

Then in deployment template you may do like that:

spec:
  env:
  {{- if .Values.some-condition }}
  - name: EXAMPLE_VAR
    valueFrom:
      secretKeyRef:
        name: "name"
        key: "key"
  {{- end }}
-- Vasily Angapov
Source: StackOverflow