Sub topic 3
Pod phases and container states
This chapter assumes you can read a Pod manifest, run kubectl, and know that a node is a machine that runs Pods. You should also know what a container image is.
Two levels of status
A Pod reports status at two levels. The phase is a coarse summary of the whole Pod. The container state describes each container on its own. Most debugging starts by comparing the two.
Pod phases
The phase is a single field, status.phase. It has five possible values.
| Phase | Meaning |
|---|---|
| Pending | The API server accepted the Pod, but at least one container is not running yet. The Pod may be waiting for a node, or pulling images. |
| Running | The Pod is bound to a node and at least one container is running, starting, or restarting. |
| Succeeded | Every container exited with code 0 and will not be restarted. |
| Failed | Every container has terminated, and at least one failed. |
| Unknown | The control plane cannot get the Pod's state, usually because the node is unreachable. |
The phase is not a health verdict. A Pod in Running can have a container that crashes every ten seconds.
Container states
Each container is in one of three states. Read them with kubectl describe pod.
- Waiting: the container is not running yet. It is pulling an image, waiting for a previous init container, or backing off after a crash. A
reasonfield explains why, such asContainerCreating,ImagePullBackOff, orCrashLoopBackOff. - Running: the container process has started.
- Terminated: the process ended. The state records an
exitCode, areasonsuch asCompletedorError, and start and finish times.
Check them with this command:
kubectl get pod web -o jsonpath='{.status.phase}{"\n"}{.status.containerStatuses[*].state}{"\n"}'The first line prints the phase. The second prints the state object of each container.
Conditions
Beyond phase and state, a Pod has conditions, each with a True or False status. The ones you will see most are PodScheduled, Initialized, ContainersReady, and Ready. Ready decides whether a Service sends traffic to the Pod. A Pod can be Running and not Ready, for example while its readiness probe is failing.
kubectl get pod web -o jsonpath='{range .status.conditions[*]}{.type}={.status}{"\n"}{end}'Common mistakes
- Treating
Runningas healthy. CheckREADYandRESTARTSinkubectl get podtoo. - Treating
CrashLoopBackOfforImagePullBackOffas phases. They are container waiting reasons. The Pod phase for both is usuallyPendingorRunning. - Expecting a
FailedPod to restart. Once the phase isFailedorSucceeded, the Pod is finished. A controller must create a replacement.
Exercise
A Pod shows STATUS CrashLoopBackOff. What is its phase likely to be, which container state explains the status, and where do you look for the exit code?
Show answer
The phase is most likely Running, because the container is repeatedly restarted. The container is in the Waiting state with reason CrashLoopBackOff while it backs off between restarts. The exit code is in the container's last terminated state, which kubectl describe pod shows under "Last State".