🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes: The Four-Move Debug Routine

The four-move debug routine is the fixed order for finding why a pod is unhappy. It runs describe, then Events, then logs, then debug or exec.

Move one is describe

Describe shows the pod state and the restart count. The Events at the bottom name the cause.

kubectl describe pod web-7d9f4b6c8-x2k9m

Move two is the Events

The Events list is the timeline of the pod. Read it from the bottom up for the latest failure.

kubectl get events --sort-by=.lastTimestamp | tail -5

Move three is logs, with previous

The current container may have no logs yet. The previous container holds the crash evidence.

kubectl logs web-7d9f4b6c8-x2k9m --previous

Move four is exec or debug

Exec runs a command inside a running container. Debug adds a helper container when exec cannot help.

kubectl exec web-7d9f4b6c8-x2k9m -- curl -s http://localhost:3000/health

Example

kubectl describe pod web-7d9f4b6c8-x2k9m
kubectl logs web-7d9f4b6c8-x2k9m --previous
kubectl exec web-7d9f4b6c8-x2k9m -- curl -s http://localhost:3000/health

Key points

  • Four-move debug routine: describe, then Events, then logs, then debug or exec, in that order every time
  • Use kubectl describe pod to see the pod state, the restarts and the Events at the bottom
  • Use kubectl logs to read what the app printed before it stopped
  • Use kubectl logs --previous to read the logs of the container that already crashed
  • Use kubectl exec to run a command inside a running container
  • Use kubectl debug to add a temporary container to a pod you cannot enter
  • Reading only kubectl get pods hides the reason, because the status shows the symptom and not the cause

In this example, the first command shows the pod waiting in CrashLoopBackOff, a restart loop taught in the next lesson. The second command reads the previous container logs. The output shows a refused database connection. The third command checks the health endpoint inside the running container. The output shows the app itself is fine, so the database connection is the fault.

Note

Events expire in about an hour, so check them while the failure is fresh.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What is the correct first move when a pod is failing?