Sub topic 5
Reading status conditions
This chapter assumes you can run kubectl get and kubectl describe, and that you know what Pods, Deployments, and Nodes are. It builds on Pod phase and container states from the previous chapters.
What a condition is
Phase is a coarse summary, and container states describe single containers. A condition is a named yes/no check about the whole object. Each entry in status.conditions has these fields:
| Field | Meaning |
|---|---|
| `type` | The name of the check, such as `Ready` |
| `status` | `"True"`, `"False"`, or `"Unknown"` (a string, not a boolean) |
| `reason` | A short CamelCase code for the cause |
| `message` | A human-readable explanation |
| `lastTransitionTime` | When `status` last changed |
A controller or the kubelet writes these fields, never you. Unknown means the reporter could not determine the answer. On a Node, for example, this happens when the kubelet stops reporting.
Pod conditions
A Pod passes through four main conditions in order:
PodScheduledis True once the scheduler has chosen a node. If it is False with reasonUnschedulable, the message says why, for example insufficient memory.Initializedis True once all init containers have finished.ContainersReadyis True when every container passes its readiness check.Readyis True when the Pod can receive traffic from Services. It also waits for any readiness gates you defined.
Read the first False condition in this order. It tells you which stage is stuck.
Reading conditions from the command line
kubectl describe pod web-0 prints a Conditions table. For scripts, use jsonpath to print one line per condition:
kubectl get pod web-0 -o jsonpath='{range .status.conditions[*]}{.type}={.status}{"\n"}{end}'Typical output for a healthy Pod:
PodReadyToStartContainers=True
Initialized=True
Ready=True
ContainersReady=True
PodScheduled=TruePhase can mislead
Phase and conditions answer different questions. This excerpt comes from a Pod whose phase is Running:
status:
phase: Running
conditions:
- type: Ready
status: "False"
reason: ContainersNotReady
containerStatuses:
- name: app
ready: false
restartCount: 5
state:
waiting:
reason: CrashLoopBackOffThe Pod is Running because at least one container has been started. It is not serving traffic because Ready is "False". The reason ContainersNotReady sends you to containerStatuses, where the container is in CrashLoopBackOff.
Conditions on other resources
The same structure appears on other kinds, but the types differ:
- Deployments report
AvailableandProgressing. - Nodes report
Ready,MemoryPressure,DiskPressure, andPIDPressure.
For Node pressure conditions, True is the bad value. For Ready, True is the good value. Read the type name before you interpret the status.
To compare Nodes at a glance, extract a single condition with custom-columns:
kubectl get nodes -o custom-columns='NAME:.metadata.name,READY:.status.conditions[?(@.type=="Ready")].status'Common mistakes
- Comparing
statusto a boolean. In a script, compare it to the string"True". - Ignoring
lastTransitionTime. A condition that flipped a few seconds ago means something different from one that has been False for an hour. - Stopping at the condition. Conditions say what is wrong, and events and logs usually say why. The next chapters cover events.
Exercise
A Pod shows phase Running, but clients get no responses through its Service. Which condition do you check first, and what does a False value there tell you?
Show answer
Check the Ready condition, for example with kubectl describe pod or the jsonpath command. If Ready is False, the Pod is not in the Service's endpoints, even though a container is running. The reason (such as ContainersNotReady) and ContainersReady show which container is failing its readiness check.
Exercise
A Node's MemoryPressure condition has status "True". Is this good or bad, and how does it differ from Ready being "True"?
Show answer
It is bad. Pressure conditions are True when the problem exists. Ready is the opposite: True means healthy. Always read the type name before interpreting the status.