Sub topic 14
Putting it together: a repeatable debugging workflow
This chapter assumes you can run kubectl get and kubectl describe. It also assumes you know the difference between spec and status, and that you have seen Pod phase, container states, conditions, and events. Here you combine them into one routine you can repeat for any broken workload.
The idea: work from wide to narrow
Status tells you what state an object is in. Events tell you what the cluster did to get there. Logs tell you what the application said. Check them in that order, and move from the whole workload down to one container.
Step 1: check the workload
Start with the controller, not the Pod.
kubectl rollout status deployment/web
kubectl get deployment web -o jsonpath='{.status.conditions[*].type}'If the rollout is stuck or Available is false, list the Pods and find the ones that are not ready.
Step 2: read the Pod status
kubectl get pod web-0 -o wide
kubectl describe pod web-0Look at these fields in order:
- Phase.
Pendingusually means scheduling or image pulling.Runningdoes not mean healthy. - Conditions. Check
PodScheduled,Initialized,ContainersReady, andReady. The first one that isFalseshows how far the Pod got. - Container state. Look for
Waitingwith a reason, orTerminatedwith an exit code. restartCountandlastState. A growing count means the container keeps failing.
Step 3: read the events
The Events section at the bottom of describe is the quickest place to start. For a time-ordered view, use one of these:
kubectl events --for pod/web-0
kubectl get events --field-selector involvedObject.name=web-0
kubectl get events -A --field-selector type=WarningStep 4: match the symptom to a cause
| What you see | Likely cause | Where to confirm |
|---|---|---|
| `Pending` with `FailedScheduling` event | No node fits the requests, taints, or selectors | Event message, then node conditions |
| `Waiting: ImagePullBackOff` | Wrong image name, tag, or registry credentials | `Failed` and `BackOff` events |
| `Waiting: CrashLoopBackOff` | The process exits repeatedly | `lastState.terminated`, previous logs |
| `lastState.terminated.reason: OOMKilled` | Memory use passed the limit | Container `resources.limits.memory` |
| `Running` but `Ready=False` | A readiness probe is failing | `Unhealthy` events |
Step 5: read the logs last
Logs matter most for containers that started and then failed. After a restart, the current container may have no output yet, so read the previous instance.
kubectl get pod web-0 -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}'
kubectl logs web-0 --previousStep 6: check the node when Pods share a symptom
If several Pods on one node fail in the same way, look at the node.
kubectl get nodes -o custom-columns='NAME:.metadata.name,READY:.status.conditions[?(@.type=="Ready")].status'
kubectl describe node worker-1Pressure conditions such as MemoryPressure or DiskPressure, and eviction events, point to a node problem instead of an application problem.
Common errors in the routine
- Stopping at
Running. Phase does not reflect failing containers or probes. Read conditions and container states too. - Reading events too late. Events expire after about an hour by default, and repeated events are merged into one entry with a count. Capture them soon after the failure.
- Reading only current logs. Use
--previousafter a restart. - Fixing the Pod instead of the template. A Pod managed by a Deployment is replaced from its template. Change the Deployment, then watch the new rollout.
Exercise
A Pod shows phase Running, but kubectl get pod shows 0/1 ready and the restart count keeps rising. List the commands you would run, in order, and what each tells you.
Show answer
1. kubectl describe pod web-0 shows the conditions, the container state, and the Events section. The state will probably be Waiting: CrashLoopBackOff. 2. kubectl get pod web-0 -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}' shows why the last instance ended, for example Error or OOMKilled. 3. kubectl logs web-0 --previous shows the output of the failed instance, which usually holds the cause. If the reason is OOMKilled, raise the memory limit or fix the leak. If the logs show an application error, fix the configuration or code.