Skip to content

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

  1. Apply crashing-pod.yaml - it will enter CrashLoopBackOff.
  2. Check the pod status using kubectl get pods and kubectl describe pod.
  3. Look at the Events section to understand why it’s crashing.
  4. Read the pod’s termination message from the last terminated state.
  5. 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 ──▶ Running ──▶ Succeeded
                │
                └──▶ Failed ──▶ CrashLoopBackOff

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:

kubectl apply -f crashing-pod.yaml
kubectl get pods --watch

Hint 2

After it crashes, read the termination message:

kubectl get pod crashing-pod -o jsonpath='{.status.containerStatuses[0].lastState.terminated.message}'

Hint 3

The password is lifecycl3.


🔓 Unlock Room 09

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_09/README             \
        -out ../room_09/README.txt        \
        -pass pass:PASSWORD
cat ../room_09/README.txt