Kubernetes
Pod Name Resolution
IP Address Lookup
Networking
DevOps

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

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Looking up a pod name from an IP address is a common debugging task during network incidents and observability investigations. The basic idea is simple: compare the target IP with pod status fields. The part that causes mistakes is making sure the IP actually belongs to a pod and not to a service or node.

Confirm What Kind of IP You Have

Before querying pod data, check whether the address is really a pod IP.

In Kubernetes, the IP might belong to:

  • a pod
  • a service
  • a node

If the target is a service ClusterIP or a node IP, a pod lookup will not return the answer you expect.

Useful checks:

bash
kubectl get svc -A -o wide
kubectl get nodes -o wide

Only after ruling those out does it make sense to search the pod list.

Do a Quick Lookup with kubectl

For ad hoc shell work, a wide pod listing is the fastest starting point.

bash
TARGET_IP="10.244.1.23"
kubectl get pods -A -o wide | grep "$TARGET_IP"

This is convenient for humans, but it is not a great format for automation because table output can change and whitespace parsing is brittle.

Use Structured Output for Reliable Matching

For a more stable terminal workflow, use JSONPath and filter exactly on the pod IP field.

bash
1TARGET_IP="10.244.1.23"
2
3kubectl get pods -A \
4  -o jsonpath='{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}' \
5| awk -v ip="$TARGET_IP" '$3==ip {print $1, $2}' ``` This returns namespace and pod name only when the IP matches exactly. That is much safer than relying on loosely formatted column output in a script. ## Use Field Selectors When Available Some clusters support selecting pods directly by `status.podIP`. ```bash kubectl get pods -A \ --field-selector=status.podIP=10.244.1.23 \ -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,IP:.status.podIP' ``` This is cleaner than client-side filtering, but field-selector behavior can vary by resource and cluster version. If it does not work in your environment, fall back to structured output filtering. ## Query the Kubernetes API for Automation For repeatable tools or incident bots, use the Kubernetes API rather than shell parsing. ```python from kubernetes import client, config config.load_kube_config() v1 = client.CoreV1Api() target_ip = "10.244.1.23" pods = v1.list_pod_for_all_namespaces(watch=False) for pod in pods.items: if pod.status.pod_ip == target_ip: print(f"{pod.metadata.namespace}/{pod.metadata.name}") ``` For in-cluster automation, use `config.load_incluster_config()` instead of loading the local kubeconfig file. ## Remember That Pod IPs Are Ephemeral A pod IP is useful for incident lookup, but it is not a durable identity. Pods can restart, move, or be replaced by a new pod with a different UID and IP. If you need long-term correlation, capture more than the IP: - cluster - namespace - pod name - pod UID - owner object such as Deployment or StatefulSet That is much more reliable than treating the IP as a stable identifier over time. ## Follow the Lookup with Pod Inspection Once you find the pod name, the next step is usually to inspect the pod and its owner. ```bash kubectl -n my-namespace describe pod my-pod-name kubectl -n my-namespace get pod my-pod-name -o yaml ``` That often reveals restarts, probe failures, scheduling issues, or owner references that explain why the pod was involved in the incident. ## Common Pitfalls The biggest pitfall is trying to look up a service IP in the pod list and assuming the lookup is broken when it returns nothing. Another common issue is searching only one namespace when the pod lives elsewhere. Incident tooling should usually search across all namespaces unless you already know the scope. People also over-trust pod IPs as long-lived identifiers even though they are temporary by design. ## Summary - First verify that the target address is actually a pod IP and not a service or node IP. - Use `kubectl` with JSONPath or field selectors for reliable shell-based lookup. - Use the Kubernetes API for repeatable automation. - Treat pod IP as an incident lookup key, not as a durable identity. - After finding the pod, inspect its namespace, owner, and recent events to continue the investigation.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.