JSON PATH
JSON PATH — practical walkthrough with examples.
These kubectl commands demonstrate how to use JSONPath expressions to extract specific fields from Kubernetes resources. The first example uses custom columns to display deployment details, and the second extracts internal IP addresses of all nodes.
1
2
3
kubectl get deploy -o custom-columns=DEPLOYMENT:.metadata.name,CONTAINER_IMAGE:.spec.template.spec.containers[*].image,READY_REPLICAS:.status.readyReplicas,NAMESPACE:.metadata.namespace --sort-by=.metadata.name > /opt/admin2406_data
kubectl get nodes -o jsonpath="{range .items[*]}{.status.addresses[?(@.type=='InternalIP')].address}{end}" > /root/CKA/node_ips
This post is licensed under CC BY 4.0 by the author.