
kubectl
How kubectl decides what to put in the STATUS column
kubectl get pods never shows status.phase. Here is the real algorithm behind the STATUS column, and why a pod reads Running while a container crash-loops.
The STATUS column in kubectl get pods is not a field. There is no status.status
in the Pod API, and it is not status.phase either — phase only has five possible
values (Pending, Running, Succeeded, Failed, Unknown), and none of them
is CrashLoopBackOff.
STATUS is computed fresh every time you run the command, from four separate fields. Knowing the algorithm explains most of the confusing output you have ever seen from it.
Where the value actually comes from
Nowhere in storage. That is the part worth internalising: no Pod in etcd carries a
status string. What surprises people is where it gets computed. It is not in your
terminal. kubectl get asks the API server for a table instead of raw objects:
Accept: application/json;as=Table;v=v1;g=meta.k8s.io,...
The API server runs the printer, fills in every cell, STATUS included, and kubectl
just lays the rows out. Turn that off with --server-print=false and the column
disappears, because kubectl has no pod printer of its own any more:
$ kubectl get pods --server-print=false
NAME AGE
config-first 59s
This is why the same pod can read differently across tools — anything that renders its own status column is re-implementing this derivation, and most implementations get the edge cases wrong.
The column is built by printPod in
pkg/printers/internalversion/printers.go, which is API server code. The logic
runs roughly like this:
Two details in there explain most surprises.
The container list is walked backwards, and it is sorted by name
The printer iterates status.containerStatuses in reverse order, and every
waiting or terminated container overwrites reason. There is no break. This is
the loop on release-1.36:
for i := len(pod.Status.ContainerStatuses) - 1; i >= 0; i-- {
container := pod.Status.ContainerStatuses[i]
...
switch {
case container.State.Waiting != nil && container.State.Waiting.Reason != "":
reason = container.State.Waiting.Reason
case container.State.Terminated != nil:
...
The last container the loop examines is index 0, so the first entry in
containerStatuses wins. And that list is not in spec order. The kubelet sorts it
by container name before writing it (sort.Sort(kubetypes.SortedContainerStatuses(...)),
which compares Name). So when several containers are failing, STATUS shows
the one whose name sorts first alphabetically, wherever you put it in the spec.
Two failing containers on a 1.36.1 kind cluster: one with an image tag that does
not exist, one referencing a ConfigMap key that does not exist. image-first and
config-first are the same pod with the spec order swapped; renamed changes only
the names:
NAME READY STATUS RESTARTS AGE
config-first 0/2 ImagePullBackOff 0 50s
image-first 0/2 ImagePullBackOff 0 50s
renamed 0/2 CreateContainerConfigError 0 50s
| Pod | Spec order | containerStatuses order | STATUS |
|---|---|---|---|
image-first | app (bad image), sidecar (bad config) | app, sidecar | ImagePullBackOff |
config-first | sidecar (bad config), app (bad image) | app, sidecar | ImagePullBackOff |
renamed | web (bad image), config-agent (bad config) | config-agent, web | CreateContainerConfigError |
Swapping the spec order changed nothing. Renaming the containers flipped the
result. So in a pod with an app and a sidecar, whose problem you see depends on
which name comes first in the alphabet: app beats istio-proxy, but web loses
to envoy.
This is why a pod can have two broken containers while STATUS only tells you about one of them, and why the fix is to stop trusting the column and look at containers individually:
kubectl get pod my-pod -o jsonpath='{range .status.containerStatuses[*]}{.name}{"\t"}{.ready}{"\t"}{.state}{"\n"}{end}'
That prints one line per container with its actual state, in the same name order. If more than one is waiting or terminated, the container STATUS reported on is the first line.
Terminating overrides nearly everything
The deletionTimestamp check happens at the end, not the beginning. A pod that is
being deleted shows Terminating regardless of what its containers are doing —
unless the phase is already Succeeded or Failed, in which case the terminal
phase wins.
This is why a crash-looping pod appears to “fix itself” the moment you delete it. It did not fix itself. It is still crash-looping. The column is just telling you about the deletion now instead.
Init containers get their own namespace of statuses
If init containers have not finished, STATUS is prefixed with Init:, and you get
one of three shapes: Init:M/N (how many completed), Init:<reason> such as
Init:CrashLoopBackOff, or Init:ExitCode:N.
One modern wrinkle: restartable init containers — sidecars declared with
restartPolicy: Always in the init section — count as done once they are running,
not once they exit. Without that rule, every pod using the sidecar pattern would sit
at Init:0/1 forever.
Why RESTARTS says “3 (5m ago)”
There is no pod-level restart counter either. RESTARTS is the sum of
restartCount across all container statuses, including init containers. The
parenthetical is the most recent lastState.terminated.finishedAt across those
containers — so it is “when the most recent restart happened”, not “when this pod
started failing”. A pod that crashed 400 times last week and once five minutes ago
reads 401 (5m ago).
Reading this correctly matters more than it looks
Every tool that shows you a pod list has to reimplement this. Get it wrong and you
show Running for something that is not running, or invent a status kubectl never
produces — which is worse, because now two tools disagree and you do not know which
one is lying.
We ported this algorithm into KubeGlance from kubectl’s source and test it against
captured API fixtures, precisely so the STATUS column in the app matches what
kubectl get pods would have told you. When they agree, you can stop double-checking.
All pod status errors, with the fix for each: Kubernetes pod status errors.
Away from your desk? KubeGlance is a native Kubernetes client for iPhone and iPad, with a full Mac app on the same core — pods, workloads, logs and events straight from your kubeconfig.
Get KubeGlanceRelated reading
- How to fix CrashLoopBackOff — the most common value this column ever shows, and what the exit code behind it means
- ImagePullBackOff and ErrImagePull — the other waiting state, and why the useful error has usually already scrolled past
- How KUBECONFIG merges multiple files — the other piece of kubectl behaviour that is computed rather than fetched
- The Pod lifecycle documentation in the Kubernetes docs covers phase, which is the input to all of the above
The Kubernetes dashboard that fits in your pocket
KubeGlance is a native Kubernetes client for iPhone and iPad — the real dashboard, not a companion — with a full Mac app on the same core. Pods, workloads, logs and events, straight from your kubeconfig.
Download KubeGlanceChoosing a Kubernetes client? Compare KubeGlance with Lens, k9s, Headlamp and Aptakube, or see the Mac and iPhone options.


