Crash Loops
Part of the Introduction to Kubernetes section of Coddy's Terminal journey. Lesson 24 of 45.
A container is expected to keep running. When its process exits, Kubernetes restarts it (the Pod's restartPolicy is Always by default). If it exits again and again, the status becomes CrashLoopBackOff and the RESTARTS column climbs, with a longer pause before each restart.
Here is a container that prints a message and fails on purpose:
kubectl run crash --image=busybox -- sh -c "echo boom; exit 1"Everything after -- is the command the container runs. List the Pods a few times and watch the status go from Running to Error to CrashLoopBackOff.
The reason is in the logs: kubectl logs crash prints boom, the last thing the container said. Even an image with nothing to run, like a plain busybox, exits at once and ends up in the same loop: a Pod needs a process that keeps running.
Challenge
EasyStart a Pod named crash from the busybox image running the command sh -c "echo boom; exit 1". Print its logs, then list the Pods twice and watch the status reach CrashLoopBackOff.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to Kubernetes
Practice on your own: Terminal playground