'Get environment variable from kubernetes pod?
What's the best way to list out the environment variables in a kubernetes pod?
(Similar to this, but for Kube, not Docker.)
Solution 1:[1]
kubectl exec -it <pod_name> -- env
Solution 2:[2]
Execute in bash:
kubectl exec -it <pod-name> -- printenv | grep -i env
You will get all environment variables that consists env
keyword.
Solution 3:[3]
Both answers have the following issues:
- They assume you have the permissions to start pod, which is not the case in a locked-down environment
- They start a new pod, which is invasive and may give different environment variables than "a[n already running] kubernetes pod"
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Robert Yi |
Solution 2 | |
Solution 3 | pyb |