CKAD Practice Question 6: Previous Container Logs
Certified Kubernetes Application Developer (CKAD) · Test 1 · question 6 of 10
A Pod named api contains two containers, web and agent. The web container is in CrashLoopBackOff. Running kubectl logs api fails asking you to choose a container, and once you name web the command returns nothing because the container is currently waiting to be restarted rather than running.
Which command shows you the output that the crashed instance produced before it exited?
Show answer and explanation
Answer:
The kubelet keeps the log file of the most recent terminated instance of a container alongside the current one. kubectl logs --previous (short form -p) reads that retained file, which is the only way to see the messages a crashing container wrote before it exited. Combining it with -c web selects the container in a multi-container Pod.
Option B does work eventually but is the wrong tool: --follow attaches to the current instance, which is not running, and it forces you to sit through another crash cycle to capture output you already have on disk.
Option C cannot run. kubectl exec needs a running container to attach to, and this one is in a back-off wait. It also assumes the application writes to a file inside the container instead of to stdout/stderr, which is the convention Kubernetes log collection relies on.
Option D is useful context; kubectl describe pod shows the previous state's exit code and reason, and the restart count, but its premise is wrong. Terminated container logs are retained until the Pod is removed from the node, which is what makes --previous possible.
Reference: Debug Running Pods