Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get environment variable from kubernetes pod?

Tags:

kubernetes

What's the best way to list out the environment variables in a kubernetes pod?

(Similar to this, but for Kube, not Docker.)

like image 793
Robert Yi Avatar asked Dec 05 '19 15:12

Robert Yi


People also ask

How do I get environment variables in Kubernetes?

We can use the 'env' or 'envFrom' field to set Kubernetes environment variables. It overrides any environment variables specified in the container image. We also have dependent environment variables. We can use $(VAR_NAME) in the value of env in a configuration file to set dependent environment variables.

How can I see environment variables in container?

Fetch Using docker exec Command Here, we are executing the /usr/bin/env utility inside the Docker container. Using this utility, you can view all the environment variables set inside Docker containers.

Do containers in a pod share environment variables?

Short answer is No, they can't.


2 Answers

kubectl exec -it <pod_name> -- env

like image 106
Robert Yi Avatar answered Oct 21 '22 15:10

Robert Yi


Execute in bash:

kubectl exec -it <pod-name> -- printenv | grep -i env

You will get all environment variables that consists env keyword.

like image 34
Sabuhi Shukurov Avatar answered Oct 21 '22 16:10

Sabuhi Shukurov