CKA Troubleshooting Practice Question
You want to check the logs of a container that previously crashed. Which command should you use?
⚠ Common exam trap
A common mix-up: candidates choose `kubectl logs <pod-name>` (option B) thinking it shows all logs, but they forget that a crashed container's logs are only accessible with the `--previous` flag.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
kubectl logs --previous <pod-name>
The `kubectl logs --previous` command retrieves logs from the previous instance of a container in a Pod that has crashed or been restarted. This is essential for debugging transient failures because the current container's logs may not contain the crash information. The `--previous` flag specifically accesses the terminated container's log stream, which is stored by the kubelet until the pod is deleted.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
kubectl logs --previous <pod-name>
Why this is correct
The `--previous` flag instructs kubectl to retrieve the logs of the last terminated container instance within the pod. When a container has crashed and restarted, the current container's logs are empty or show only new output, while the terminated container's logs remain accessible via this flag. This is the correct way to diagnose why the previous container failed, as it directly fetches the stdout/stderr stream from that dead instance.
- ✗
kubectl logs <pod-name>
Why it's wrong here
Running `kubectl logs <pod-name>` without `--previous` fetches only the logs from the currently running container. If the container has crashed and restarted, this command will show the logs of the new (current) container only, missing the error messages from the crashed instance that led to the failure. It is useful for live troubleshooting but cannot reveal the historical output of a terminated container, making it insufficient for this scenario.
- ✗
kubectl exec <pod-name> -- cat /var/log/app.log
Why it's wrong here
`kubectl exec` requires a running container to establish an interactive session and execute a command. A crashed container is in a terminated state, so the API server cannot start a process inside it, and the command will fail with an error like 'cannot exec into a container in a completed/pending/failed state'. Even if the container had a persistent volume with logs, exec cannot reach the crashed instance; you must use the `--previous` flag on `kubectl logs` instead.
- ✗
kubectl describe pod <pod-name>
Why it's wrong here
`kubectl describe pod` aggregates pod status, events, conditions, and container metadata from the Kubernetes API, but it does not expose container stdout/stderr logs. While events may indicate why a container restarted (e.g., OOMKilled), they are often too coarse to capture the actual application error trace. To see the exact log output from the crashed container, you must use the logs API with `--previous`; describe is a complement, not a replacement.
Go deeper
Related to this question
Learn chapter
Storage Basics and Volumes
Key term
kubectl Command Reference
kubectl is the command-line tool used to interact with and manage Kubernetes clusters by sending commands to the Kubernetes API.
Key term
Log Analysis
Log analysis is the process of reviewing and interpreting system-generated records to understand what happened in an application or infrastructure.
About these practice questions
This CKA question is part of Courseiva's 302-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CKA practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKA exam.