json – parsing jsonpath with kubectl
I would try to keep it simple by using custom-columns
:
kubectl get pod -o custom-columns="POD-NAME":.metadata.name,"NAMESPACE":.metadata.namespace,"CONTAINER-IMAGES":.spec.containers[*].image,"DNS-POLICY":.spec.dnsPolicy
POD-NAME NAMESPACE CONTAINER-IMAGES DNS-POLICY
bar default nginx ClusterFirst
foo default nginx ClusterFirst
zoo default nginx,ubuntu ClusterFirst
Using jsonpath
:
kubectl get pod -o jsonpath="{range .items[*]}{.metadata.name},{.spec.containers[*].image},{.spec.dnsPolicy}{"\n"}{end}"
bar,nginx,ClusterFirst
foo,nginx,ClusterFirst
zoo,nginx ubuntu,ClusterFirst
Read more here: Source link