Error when running Helm Chart with environment variables

12/13/2019

I am creating a Helm Chart (v3) for a Kubernetes Deployment. In the deployment.yaml I am defining some environment variables

spec:
  ...  
    env:
      - name: GRAPHITE_ENABLED
        value: {{ .Values.env.graphiteEnabled }}
      - name: GRAPHITE_HOSTNAME
        value: {{ .Values.env.graphiteHostname }}

and specifying values for these environment variables in values.yaml

env:
  graphiteEnabled: "false"
  graphiteHostname: "localhost"

When running the Chart using this command

helm install --debug api-test ./rest-api

the following error is caused:

Error: Deployment in version "v1beta1" cannot be handled as a Deployment: v1beta1.Deployment.Spec: v1beta1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.Value: ReadString: expects " or n, but found f

-- LazerBass
kubernetes-helm

1 Answer

12/13/2019

Turned out the issue was cause by the value "false".

After a --dry-run I saw that the output of the generated values was

- name: GRAPHITE_ENABLED
  value: false

But the environment variable must be defined with quotes.

Using the quote function for the value in the values.yaml fixed the issue

- name: GRAPHITE_ENABLED
  value: {{ .Values.env.graphiteEnabled | quote }}

which generated the following output

- name: GRAPHITE_ENABLED
  value: "false"
-- LazerBass
Source: StackOverflow