haruhi:
In regards to these JSON path questions, what’s a good way to quickly find keys in JSON output? For example, if I’m trying to find Internal IP addresses of nodes in the cluster, how would I know what key to look for without manually parsing the JSON for the correct key?
Vivekanand Rapaka:
# Helpful when locating a key within a complex nested JSON structure
kubectl get nodes -o json | jq -c 'path(..)|[.[]|tostring]|join(".")'
# Produce a period-delimited tree of all keys returned for pods, etc
kubectl get pods -o json | jq -c 'path(..)|[.[]|tostring]|join(".")'
Vivekanand Rapaka:
you can use | jq -c ‘path(…)|[.[]|tostring]|join(“.”)’ for the command
haruhi:
thanks!
unnivkn:
you have this in cheat sheet:
# Get ExternalIPs of all nodes
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
just change External to Internal
You can use
kubectl get nodes -o json | jq -c ‘path(…)’
to see all the possible jsonpaths… then use the path in the command below:
kubectl get nodes --output=jsonpath={.items…metadata.name}
It is not clean , but easy to remember.