Get an environment variable from kubernetes pods and store it in an array Get an environment variable from kubernetes pods and store it in an array kubernetes kubernetes

Get an environment variable from kubernetes pods and store it in an array


You can retrieve this information using the following command:

kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{.spec.containers[*].env[*].name}{"\t"}{.spec.containers[*].env[*].value}{"\n"}{end}' | grep COUNTRY | cut -f 2

It will return the variables content as follows:

$ kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{.spec.containers[*].env[*].name}{"\t"}{.spec.containers[*].env[*].value}{"\n"}{end}' | grep VAR | cut -f 21234567890123


 kubectl get pods -o=jsonpath='{.items[*].spec.containers[*].env[?(@.name=="COUNTRY")].value}'

Hope this helps. I was just able to run it on mine and it worked the best.