How to get the status of a particular pod or container kubectl get pods using jsonpath
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
kubectl get ... -o jsonpath=... is useful when you need one exact status field instead of the full default table. The important part is knowing whether you want pod-level status, such as Running, or container-level status, such as readiness, restart count, waiting reason, or exit code.
Those are different paths in the Kubernetes object. If you query the wrong level, you can get a technically correct answer that still hides the actual problem.
Start With Pod Phase
If you only need the overall pod phase, query .status.phase.
Typical output might be:
This is useful for a quick health check, but it is not enough when one container inside the pod is crashing or not ready.
Query Multiple Pod Phases
If you want a compact list of pod names and their phases:
That is a common scripting pattern because it avoids parsing the full JSON output externally.
Container Status Lives Under containerStatuses
Detailed container information is stored in .status.containerStatuses. If a pod has multiple containers, each one has its own readiness flag, restart count, and current state.
To print the readiness of the first container:
To print the name and readiness of every container:
This is often more useful than .status.phase, because a pod can be in Running phase while one container is unhealthy.
Waiting Reasons And Exit Codes
When you are debugging a failing pod, waiting and termination reasons are often the real answer. Those values live under .state.waiting and .state.terminated.
Get the waiting reason of the first container:
Get the termination reason and exit code:
These are the fields that tell you whether you are dealing with CrashLoopBackOff, image pull problems, or a process exiting with a nonzero code.
Restart Count Is Often The Fastest Signal
Restart count is one of the quickest ways to see whether a pod looks stable:
A pod may still be technically running while a container restarts repeatedly, so restart count is worth checking early.
Namespace And Discovery Matter
If the pod is not in the default namespace, include the namespace explicitly:
When you are unsure about the path, inspect the full object:
Finding the exact field in the full JSON is usually faster than guessing nested JSONPath expressions from memory.
When jsonpath Stops Being Pleasant
kubectl JSONPath is convenient for direct field extraction, but it becomes awkward when you want complex filtering inside nested arrays, especially by container name. If you reach that point, jq, -o go-template, or a small script may be clearer than forcing more complexity into jsonpath.
That is not a failure of the command. It is simply the point where a lightweight extraction tool stops being the best tool.
Common Pitfalls
One common mistake is checking only .status.phase and assuming the pod is healthy. Another is forgetting that container details live under .status.containerStatuses, not directly under .status. Developers also often query the wrong namespace and then conclude the pod or field is missing. Finally, some scripts try to make kubectl JSONPath do deep filtering that jq would handle much more cleanly.
Summary
- Use
.status.phasefor the overall pod phase. - Use
.status.containerStatusesfor readiness, restart counts, waiting reasons, and exit codes. - Include
-n namespacewhen the pod is not in the default namespace. - Inspect the full JSON when building a new JSONPath expression.
- Switch to
jqor templates when nested filtering becomes too awkward forkubectlJSONPath.
Related reading
- How to gracefully remove a node from Kubernetes?
- How to handle database migrations with Kubernetes and Skaffold
- How to handle S3 events inside a Kubernetes Cluster?
- How to identify schedulable nodes in Kubernetes
- How to improve random number generation in kubernetes cluster containers?
- How to include files outside of Docker's build context?
- How to handle a situation of feature scaling in machine learning model deployment when you have only one testing instance?
- How to handle data migrations in distributed microservice databases

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.