Search code examples
kubernetesenvironment-variableskubectl

kubectl run - How to pass all the ENV variables of the hosting shell to the pod?


It is possible to pass some ENV variables to the pod via the --env option of kubectl run, for example:

kubectl run -ti --rm test --image=busybox --env location=city --env time=morning --namespace default -- sh

I would like to send all the present ENV variables to the pod without specifying all of them the via --env, especially for those that I might not know the variable name. Is there an way to do so? Thanks


Solution

  • You could try something like this:

    kubectl run -ti --rm test --image=busybox $(printenv | xargs -I % echo '--env' "%" | tr '\n' ' ') --namespace default -- sh