Reputation: 428
I'm trying to get the ip address of pods with particular label using jsonpath with the following command:
kubectl get pods -l app=validate -n {namespace_name} -o jsonpath={.status.podIP}
But this doesn't result into anything, even though the namespace and label names are correct. On the other hand, if I try to do:
kubectl get pod/pod_name -n {namespace_name} -o jsonpath={.status.podIP}
I'm able to get the pod IP address after that. But the problem is, since I'm trying to query all the pods created for a particular deployment, I want to fetch Ip addresses for all the pods under that particular label. I'm not sure what is wrong with the command.
Upvotes: 3
Views: 3508
Reputation: 352
According to the official doc, you can add custom columns when querying a list of resources.
So you can do kubectl get pods -l app=validate -n {namespace_name} -o custom-columns=ip:.status.podIP
Upvotes: 2
Reputation: 1457
If you have multiple Pods with the same label, you get a list of Pods. You have to adjust your jsonpath to -o jsonpath="{.items[*].status.podIP}"
to get all the podIPs.
Upvotes: 11