admin管理员组

文章数量:1287595

How to expand environment variables coming from a secret store and pass them inside a docker container?. Said docker container does not have a shell, therefore it is not possible to run a script. This is the sample yaml file

        envFrom:
        - secretRef:
            name: secret     
        command: ["my-command"]
        args:
          - "--env=ENV1=${MY_ENV_VAR1}"
          - "--env=env2=${MY_ENV_VAR2}"

How to expand environment variables coming from a secret store and pass them inside a docker container?. Said docker container does not have a shell, therefore it is not possible to run a script. This is the sample yaml file

        envFrom:
        - secretRef:
            name: secret     
        command: ["my-command"]
        args:
          - "--env=ENV1=${MY_ENV_VAR1}"
          - "--env=env2=${MY_ENV_VAR2}"

Share Improve this question edited Feb 25 at 0:40 David Maze 160k45 gold badges243 silver badges287 bronze badges asked Feb 24 at 18:41 TucanTucan 1721 silver badge11 bronze badges 1
  • Where does MY_ENV_VAR1 actually come from? What do you expect to set it? The args: setting sort of suggests the program expects an actual environment variable, can you use env: [{ name: ENV1, valueFrom: ... }] to set the variables without trying to wire them through command-line arguments? – David Maze Commented Feb 24 at 19:46
Add a comment  | 

1 Answer 1

Reset to default 3

You can pass environment variables to your arguments by using parentheses () instead of braces {}

    envFrom:
    - secretRef:
        name: secret     
    command: ["my-command"]
    args:
      - "--env=ENV1=$(MY_ENV_VAR1)"
      - "--env=env2=$(MY_ENV_VAR2)"

Kubernetes docs have an example here for reference: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#use-environment-variables-to-define-arguments

本文标签: kubernetespassing env variable to docker image from k8 secret storeStack Overflow