Sub topic 3
A repeatable triage sequence
This chapter assumes you know pods, deployments, and namespaces. It also assumes you can read YAML and run kubectl get and kubectl apply. You should know what a container image and a registry are.
When a pod fails, the status column gives you a symptom, not a cause. A fixed sequence of four commands moves you from the symptom to the cause. It also stops you from guessing.
The four steps
Each step answers a different question. Run them in this order.
kubectl get pod -o wideshows the status, restart count, and node. A pod with no node is not scheduled yet.kubectl describe podshows container state, last state, and the Events section at the bottom.kubectl get eventslists events for the pod in time order. Use it whendescribeoutput has scrolled away or has been trimmed.kubectl logsshows what the application printed.
kubectl get pod web -o wide
kubectl describe pod web
kubectl get events --field-selector involvedObject.name=web --sort-by=.lastTimestamp
kubectl logs webWhat each step tells you
| Step | Question it answers | Typical clue |
|---|---|---|
| `get -o wide` | Is the pod placed on a node? How often has it restarted? | `NODE` is `<none>`, `RESTARTS` is climbing |
| `describe` | Which state is the container in, and why? | `Reason: ImagePullBackOff`, `Exit Code: 137` |
| `get events` | What did the cluster do, and when? | `FailedScheduling`, `Failed to pull image` |
| `logs` | What did the application say before it stopped? | A stack trace or a missing config message |
The order matters because the cluster components write events, and the application writes logs. A pod that never started has events but no logs. Running kubectl logs first on a Pending pod gives you an error and no information.
Reading the output as a branch point
After step 2 you usually know which branch to follow.
- No node assigned and a
FailedSchedulingevent: follow the Pending path. ErrImagePullorImagePullBackOffas the waiting reason: follow the image path.- Restarts above zero and a terminated last state: follow the crash path, and use
kubectl logs --previousfor the crashed instance.
Add -n <namespace> to every command if the pod is not in your current namespace. A common mistake is to triage the wrong pod because a same-named pod exists in another namespace.
Exercise
A pod shows STATUS: Pending and NODE: <none>. Which of the four triage commands will give you a useful reason, and which one will not?
Show answer
kubectl describe pod and kubectl get events give the reason, usually a FailedScheduling event that explains why no node fits. kubectl logs will not help, because no container has been created yet and so there is no output.