Sub topic 3
Pod phase: Pending, Running, Succeeded, Failed
This chapter assumes you can run kubectl get and kubectl describe, and that you know what a Pod, a container, and a Node are. It covers the Pod phase field: what each value means and what it does not tell you.
What the phase is
Every Pod has a status.phase field. It is a coarse summary of where the Pod is in its life. The kubelet (the agent on each Node) and the control plane write it. You never set it yourself.
The phase is one of five values:
| Phase | Meaning |
|---|---|
| Pending | The API server accepted the Pod, but one or more containers are not running yet. The Pod may be waiting to be scheduled, or it may be pulling images. |
| Running | The Pod is bound to a Node and all containers have been created. At least one container is running, starting, or restarting. |
| Succeeded | All containers terminated with exit code 0 and will not be restarted. |
| Failed | All containers have terminated, and at least one ended in failure (a non-zero exit code or a system kill). |
| Unknown | The control plane cannot get the Pod's state, usually because it cannot reach the Node. |
Unknown is rare in current clusters. The other four are the ones you will see daily.
Phase transitions
A Pod moves forward through phases. It does not go back from Running to Pending.
Succeeded and Failed are terminal. Pods owned by a Deployment normally stay in Running. Pods owned by a Job end in Succeeded or Failed.
Reading the phase with kubectl
The get command shows a summary in the STATUS column:
kubectl get pod web-0 -o wideTo read only the phase, use jsonpath:
kubectl get pod web-0 -o jsonpath='{.status.phase}{"\n"}'To list all Pods in a given phase across the cluster, use a field selector:
kubectl get pods -A --field-selector status.phase=FailedThe STATUS column is not the phase
This is the most common source of confusion. The STATUS column in kubectl get pods is not always the phase. kubectl computes it from several fields. It can show CrashLoopBackOff, ImagePullBackOff, ContainerCreating, or Terminating, and none of these are phases.
Here is a status excerpt from a Pod that is failing:
status:
phase: Running
conditions:
- type: Ready
status: "False"
reason: ContainersNotReady
containerStatuses:
- name: app
ready: false
restartCount: 5
state:
waiting:
reason: CrashLoopBackOff
lastState:
terminated:
reason: Error
exitCode: 1The phase is Running, yet the Pod is not healthy. The container keeps crashing and restarting, so the Pod stays in Running. Phase only says that the Pod was bound to a Node and its containers were created. It does not say the application works.
Why a Pod stays Pending
Pending covers two different situations:
- The scheduler has not placed the Pod on a Node. Typical causes are insufficient CPU or memory, node selectors that match nothing, or taints the Pod does not tolerate. The events show
FailedScheduling. - The Pod is on a Node, but the containers have not started. The kubelet may still be pulling images or waiting for volumes to mount.
To tell the two apart, check whether the Pod has a Node assigned:
kubectl get pod web-0 -o jsonpath='{.spec.nodeName}{"\n"}'An empty result means the Pod is unscheduled. A Node name means the problem is on the Node side, so read the container states and events.
Failed and Succeeded in practice
With restartPolicy: Never or OnFailure, a finished Pod stays in the API with its terminal phase so you can read its logs. Pods that Jobs create are the usual case. With restartPolicy: Always, which Deployments require, containers are restarted after they exit. The Pod therefore does not normally reach a terminal phase.
A Pod evicted from a Node, for example under memory pressure, also ends up as Failed. The status.reason field then holds Evicted.
Exercise
A Pod shows STATUS CrashLoopBackOff in kubectl get pods. What is its phase most likely to be, and what command shows you the phase directly?
Show answer
The phase is most likely Running, because the containers were created and are being restarted. CrashLoopBackOff is a container waiting reason, not a phase. Run kubectl get pod <name> -o jsonpath='{.status.phase}' to read the phase.
Exercise
A Pod has been Pending for ten minutes. Which field tells you whether the scheduler has placed it on a Node?
Show answer
spec.nodeName. If it is empty, the Pod is unscheduled and you should look for FailedScheduling events. If it is set, the Pod is on a Node and the delay is in image pulls, volumes, or container startup.