KubectlJqContainersMatchingEnvironment

nicolaw 21st July 2021 at 12:54pm
jq JSON json kubectl Kubernetes

Show environment variable names for all pod containers where the MY_VARIABLE environment variable defined on any of the pod containers.

kubectl get pods -A -o json | jq -r '[.items[]|select(..|.name? == "MY_VARIABLE")|{container: .metadata.name, env: [.spec.containers[]|.env[].name]}]'

Show environment variable names for all pod initContainers where the MY_VARIABLE environment variable defined on any of the pod containers.

kubectl get pods -A -o json | jq -r '.items[]|select(..|.name? == "MY_VARIABLE")|{initContainer: .metadata.name, env: [(.spec.initContainers[]|.env[].name)?]}'