Kubernetes
Kubectl
Pods
jsonpath
IP Address

Not able to fetch ip address of pods using Kubectl and jsonpath

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

If kubectl is not returning pod IP addresses through JSONPath, the problem is usually one of three things: the field path is wrong, the command is targeting a list when you wrote a single-object path, or the pod does not have an IP yet. The correct field is under .status, and whether you use .items[*] depends on whether the command returns multiple pods or one specific pod.

Use the Correct Field Path

For a single pod, the IP address lives at .status.podIP.

bash
kubectl get pod my-pod -o jsonpath='{.status.podIP}'

If you also want the pod name in the output:

bash
kubectl get pod my-pod -o jsonpath='{.metadata.name}{"\t"}{.status.podIP}{"\n"}'

A common mistake is to try .podIP or .spec.podIP. Those paths are wrong, so the command returns nothing and does not always explain why.

Query Multiple Pods With .items[*]

When the command returns a list, the JSON output contains an items array. That is why the JSONPath changes.

bash
kubectl get pods -o jsonpath='{.items[*].status.podIP}'

That prints the IPs for all pods in the current namespace. If you want one formatted line per pod, use a range expression.

bash
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}'

If you need namespace information too:

bash
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}'

Check Whether the Pod Actually Has an IP

A correct JSONPath still returns an empty value if the pod is not ready for networking. Pods in Pending often have no IP address yet.

bash
kubectl get pod my-pod -o jsonpath='{.status.phase}'

If the result is Pending, check scheduling and events.

bash
kubectl describe pod my-pod

The lack of a pod IP may have nothing to do with JSONPath. The pod may simply not have been scheduled, or the cluster networking plugin may not have assigned an address yet.

Handle Common Variations

If the pod uses hostNetwork: true, the relevant address may be the host IP instead of a normal pod-network IP.

bash
kubectl get pod my-pod -o jsonpath='{.status.hostIP}'

If you are working in a dual-stack cluster, you may also need the plural field.

bash
kubectl get pod my-pod -o jsonpath='{.status.podIPs[*].ip}'

That returns all assigned pod IPs instead of only the primary one.

Use Simpler Output Modes When Debugging

If JSONPath syntax is getting in the way, use a simpler output mode first to confirm the data exists.

bash
kubectl get pods -o wide

or:

bash
kubectl get pods -o custom-columns=NAME:.metadata.name,IP:.status.podIP,NODE:.spec.nodeName

These are often easier to read during debugging. Once you confirm the field exists, move back to JSONPath for scripts or automation.

Common Pitfalls

The most common mistake is forgetting that .status.podIP is nested under .status. Another is using a list-style path like .items[*] when the command returns a single pod object, or the reverse.

Shell quoting is another frequent source of pain. Wrap the JSONPath in single quotes so the shell does not interfere with the braces and escape sequences.

Finally, do not assume every pod should already have an IP. A pod that is still pending, unschedulable, or blocked by CNI problems can correctly return an empty value.

Summary

  • For one pod, use .status.podIP.
  • For multiple pods, use .items[*].status.podIP or a range expression.
  • Check pod phase if the field is empty, because the pod may not have an IP yet.
  • Use .status.hostIP or .status.podIPs for special cases such as host networking or dual-stack clusters.
  • Fall back to -o wide or custom-columns when debugging field paths.

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.