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
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.
Execute in bash:
kubectl exec -it <pod-name> -- printenv | grep -i env
You will get all environment variables that consists env
keyword.
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