Courseiva
TroubleshootingmediumMultiple ChoiceObjective-mapped

CKA Troubleshooting Practice Question

A developer reports that a Pod named 'web-pod' in namespace 'frontend' is crashing repeatedly. You run 'kubectl logs web-pod -n frontend' but see no output. Which command should you run next to see the logs from the previous, crashed container instance?

⚠ Common exam trap

Watch out — candidates often think `kubectl logs` without flags is sufficient, or they may confuse `--previous` with `-c` (container name), not realizing that `--previous` is specifically designed to access logs from a terminated container instance, while `-c` only selects a container within a multi-container Pod.

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 web-pod -n frontend --previous

The `kubectl logs --previous` flag retrieves logs from the previous instance of a container in a Pod, which is exactly what you need when the current container has crashed and restarted, leaving no logs from the current instance. Since `kubectl logs web-pod -n frontend` returned no output, the current container likely started fresh after a crash, and the logs from the crashed container are stored in the terminated container's log file. This flag accesses those logs without needing to specify a container name explicitly when there is only one container in the Pod.

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 get events -n frontend --sort-by=.metadata.creationTimestamp

    Why it's wrong here

    While retrieving sorted namespace events is highly useful for identifying lifecycle transitions, scheduling issues, or OOMKills, it only provides high-level cluster event metadata. It does not capture stdout or stderr streams from the application itself, which are necessary to diagnose internal application crashes.

  • kubectl logs web-pod -n frontend --previous

    Why this is correct

    This command is the correct approach because the --previous (or -p) flag instructs the kubelet to retrieve the stdout and stderr logs from the most recently terminated instance of the container. This is essential for diagnosing CrashLoopBackOff states where the current container has restarted and its active log buffer is empty or irrelevant.

  • kubectl logs web-pod -n frontend -c web-pod

    Why it's wrong here

    Specifying the container name with -c is redundant if the pod only has a single container, and more importantly, this command defaults to fetching logs from the currently running container instance. If the container has crashed and restarted, this will only display the logs of the new, active instance, missing the critical error messages that caused the prior crash.

  • kubectl exec -it web-pod -n frontend -- sh

    Why it's wrong here

    Attempting to open an interactive shell session via kubectl exec requires the target container to be in a running state. If the pod is continuously crashing or in a CrashLoopBackOff state, the API server will fail to establish the connection, making it impossible to inspect the container's internal state or log files directly.

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 →

How Courseiva writes practice questions · Editorial policy

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.