The use case is to get the environment variable *COUNTRY from all the pods running in a namespace
kubectl get pods podname -n namespace -o 'jsonpath={.spec.containers[0].env[?(@.name~="^COUNTRY")].value}'
This does not seem to work. any lead?
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.
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 2
123456
7890123