Search code examples
kuberneteskubernetes-helm

Kubernetes init container issue with environment variables


I am trying to add a init container to a deployment, but I can´t make the env vars work for some reason.

Just to illustrate, this is what I am trying:

initContainers:
    - name: init-db
      image: mysql:5.7
      env:
        - name: TEST
          value: nada
      args: ["echo", "${TEST}"]

But no matter what I do, the env vars doesn´t work, the echo always returns ${TEST} instead of nada

Any hint?


Solution

  • Like the comments and other answer mentioned you need to use shell for ENV substitution properly. therefore, replace the line

    args: ["echo", "${TEST}"] in you code to

    command: ['sh', '-c', 'echo ${TEST}']

    Reference