Courseiva
Troubleshooting →easyMultiple Select

CKA Troubleshooting Practice Question

Which TWO of the following kubectl commands can be used to view the logs of a container in a pod? (Choose two.)

⚠ Common exam trap

It's easy for candidates to confuse `kubectl exec` with `kubectl logs`, thinking they can run a 'logs' command inside the container, or they may mistakenly believe `kubectl describe` includes log output, when in fact it only shows events and container state.

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 pod-name

Option B, `kubectl logs pod-name`, is correct because the `kubectl logs` command is the dedicated subcommand for retrieving the stdout/stderr output of a container in a pod, and with a single container it defaults to that container. Option E, `kubectl logs pod-name --previous`, is also correct because the `--previous` (or `-p`) flag retrieves the logs from the previous, terminated instance of the container in the pod, which is still a valid way to view container logs. Option A, `kubectl describe pod pod-name`, is not correct because describe shows pod metadata, events, and status, not the container's log stream. Option C, `kubectl exec pod-name -- logs`, is not correct because it attempts to run a `logs` binary inside the container rather than using the Kubernetes logs API. Option D, `kubectl get pod pod-name -o yaml`, is not correct because it only outputs the pod's YAML manifest/status, not its container logs.

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 describe pod pod-name

    Why it's wrong here

    While this command is highly useful for troubleshooting pod scheduling, lifecycle events, and volume mounts, it does not stream or display stdout/stderr application logs. Instead, it queries the Kubernetes API server to aggregate metadata, status conditions, and recent cluster events associated with the specified pod.

  • ✓

    kubectl logs pod-name

    Why this is correct

    This is the standard command used to retrieve the stdout and stderr streams from the primary container running inside a pod. If the pod contains multiple containers, you must specify the target container using the `-c` or `--container` flag, otherwise it defaults to the first container defined in the spec.

  • ✗

    kubectl exec pod-name -- logs

    Why it's wrong here

    This command attempts to execute an interactive or non-interactive binary named `logs` directly inside the container's filesystem. Because `logs` is not a standard Unix utility or shell command, this execution will fail with an executable file not found error unless a custom binary with that exact name was explicitly built into the container image.

  • ✗

    kubectl get pod pod-name -o yaml

    Why it's wrong here

    This command retrieves the live configuration and state of the pod resource directly from the etcd database, formatting the output as a YAML manifest. While it provides critical details like environment variables, volume mounts, and status fields, it does not capture or expose the runtime console output generated by the application.

  • ✓

    kubectl logs pod-name --previous

    Why this is correct

    This command is essential for diagnosing application crashes, such as CrashLoopBackOff states, by retrieving the logs of a prior, terminated instance of the container. The kubelet retains the log files of the immediately preceding container execution on the node, allowing administrators to inspect the stack trace or error that caused the exit before the container restarted.

About these practice questions

Courseiva writes every CKA question from scratch — 726 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.