Room 08
POD LIFECYCLE
The Circle of Life
- Pods go through distinct phases: Pending → Running → Succeeded/Failed.
- A misbehaving pod keeps crashing. Debug it to find the password hidden in its termination message.
📜 Mission Briefing
- Apply
crashing-pod.yaml- it will enter CrashLoopBackOff. - Check the pod status using
kubectl get podsandkubectl describe pod. - Look at the Events section to understand why it’s crashing.
- Read the pod’s termination message from the last terminated state.
- The termination message contains the password.
hint:
kubectl get pod NAME -o jsonpath='{.status.containerStatuses[0].lastState.terminated.message}'
Key Commands
| Command | Purpose |
|---|---|
kubectl get pods --watch |
Watch pod state changes |
kubectl describe pod NAME |
Events and status details |
kubectl logs NAME --previous |
Logs from previous (crashed) container |
kubectl get pod -o jsonpath='{.status.phase}' |
Get pod phase |
kubectl delete pod NAME --grace-period=0 --force |
Force delete |
Pod Lifecycle Phases
Pending: Pod accepted but containers not running yet (image pulling, scheduling).
Running: At least one container is running.
Succeeded: All containers terminated successfully (exit code 0).
Failed: At least one container terminated with error.
Unknown: Pod state cannot be obtained (node communication failure).
# Restart Policies
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
restartPolicy: Always # Always (default), OnFailure, Never
terminationGracePeriodSeconds: 30
containers:
- name: main
image: busybox
command: ['sh', '-c', 'echo "Password: lifecycl3" > /dev/termination-log; exit 1']
lifecycle:
postStart:
exec:
command: ['/bin/sh', '-c', 'echo "Container started"']
preStop:
exec:
command: ['/bin/sh', '-c', 'echo "Container stopping"; sleep 5']
# Check pod phases
kubectl get pods -o custom-columns=\
NAME:.metadata.name,\
PHASE:.status.phase,\
RESTARTS:.status.containerStatuses[0].restartCount
# View termination message
kubectl get pod crashing-pod -o jsonpath='{.status.containerStatuses[0].lastState.terminated.message}'
# Debug CrashLoopBackOff
kubectl describe pod crashing-pod # check Events
kubectl logs crashing-pod --previous # logs from last run
Hints
Hint 1
Apply the crashing pod and watch it:
Hint 2
After it crashes, read the termination message:
Hint 3
The password is lifecycl3.