Search code examples
kubernetes-helm

Helm chart not allowing me to consume values with special characters ex '/' or '='


I am trying set the below value in values.yaml

ex:

envVar: KY13o5+J/jHpg==

Try to consume that value in deploy.yaml file as

.
.
containers:
  - name: 'app-container'
    .
    .
    env:
      - name: ACCESS_KEY
        value: {{ .Values.envVar }}

The ACCESS_KEY gets passed to container as env variable if I don't use characters like / and =. If I use those characters than the ACCESS_KEY env variable will not be available on running container.

I need a way to escape those two characters. I tried using \ and it worked fof / but not for =.

Note: I am not facing any problems with +. I am facing this problem on deploying the container to Kubernetes cluster.


Solution

  • Try using quote string function to escape special characters in env vars

    env:
      - name: ACCESS_KEY
        value: {{ .Values.envVar | quote }}
    

    Update: Even without quotes, env var is properly loaded. Are you facing issues reading this variable?

    pod.yaml

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pod
    spec:
      containers:
        - name: test-container
          image: k8s.gcr.io/busybox
          command: [ "/bin/sh", "-c", "env" ]
          env:
            - name: ACCESS_KEY
              value: {{ .Values.envVar }}
    

    kubectl logs --previous test-pod -n test

    SHLVL=1
    HOME=/root
    ACCESS_KEY=KY13o5+J/jHpg==
    KUBERNETES_PORT_443_TCP_ADDR=172.20.0.1
    ...