What's the best way to list out the environment variables in a kubernetes pod?
(Similar to this, but for Kube, not Docker.)
What's the best way to list out the environment variables in a kubernetes pod?
(Similar to this, but for Kube, not Docker.)
kubectl exec -it <pod_name> -- env
-it flags. The best answer is actually Egor Stambakio's in the OP comments (it also covers when in a namespace).Both answers have the following issues:
To inspect a running pod and get its environment variables, one can run:
kubectl describe pod <podname>
This is from Alexey Usharovski's comment.
I am hoping this gives more visibility to your great answer. If you would like to post it as an answer yourself, please let me know and I will delete mine.
envFrom.kubectl set env can be used for both setting environment variables and reading them .
You can use kubectl set env [resource] --list option to get them.
For example to list all environment variables for all PODs in the DEFAULT namespace:
kubectl set env pods --all --list
or for an specific POD in a given namespace
kubectl set env pod/<pod-NAME> --list -n <NAMESPACE-NAME>
or for a deployment in DEFAULT namespace
kubectl set env deployment/<deployment-NAME> --list
this is better than running command inside the POD as in some cases the OS command may not exist in very slim containers
For more see : https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#set
set env command isn't working (in my case ENVs were from the config map).--list --resolve flags to the commands to resolve the secrets as Gerhard Powell suggested in his answer.Execute in bash:
kubectl exec -it <pod-name> -- printenv | grep -i env
You will get all environment variables that consists env keyword.
printenv is installed in the container.I have two ways that I get the configurations:
List all the pods with their environment variables. It also resolves the secret or configmap references
kubectl set env pods --all --list --resolve
List all the pods in a table with its enviroment variables and arguments
kubectl get pods -n qa -o custom-columns=NAME:.metadata.name,command:.spec.containers[*].command,ENV:.spec.containers[*].env,ARGS:.spec.containers[*].args`
Because Kubernetes deployments or statefulsets usually manage pods, and pods inherit the variables from their manifests, I would use the kubectl describe ... instead of kubectl exec -it ... approach since finding the correct dynamic pod name is not always easy or fast.
For example:
kubectl describe deployment/my-app -n my_namespace | grep MY_VAR_NAME
is more robust and works better for me.
kubectl -n <namespace> exec <pod_name> -- env?kubectl describe pod <podname>.