How do you get a Kubernetes pod’s name from its IP address?

Example:

kubectl get pods -o wide
NAME                               READY     STATUS    RESTARTS   AGE       IP            NODE
alpine-3835730047-ggn2v            1/1       Running   0          5d        10.22.19.69   ip-10-35-80-221.ec2.internal 

get pod name by IP

kubectl get --all-namespaces  --output json  pods | jq '.items[] | select(.status.podIP=="10.22.19.69")' | jq .metadata.name
"alpine-3835730047-ggn2v"

get container name by IP

kubectl get --all-namespaces  --output json  pods | jq '.items[] | select(.status.podIP=="10.22.19.69")' | jq .spec.containers[].name
"alpine"

Leave a Comment

tech