KCNA Kubernetes Fundamentals Practice Question
You want to view the logs of a running pod named 'my-pod'. Which kubectl command should you use?
⚠ Common exam trap
Many candidates confuse `kubectl exec` with `kubectl logs`, thinking they need to manually cat a log file inside the container, when Kubernetes automatically captures stdout/stderr and provides a dedicated `kubectl logs` command for that purpose.
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 my-pod
The `kubectl logs my-pod` command is the correct way to retrieve the standard output and standard error logs from a running pod in Kubernetes. It directly fetches the container logs from the kubelet, which are stored on the node and rotated by the container runtime (e.g., containerd or CRI-O). This is the dedicated command for log inspection, as defined in the Kubernetes CLI documentation.
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 exec my-pod -- cat /var/log/container.log
Why it's wrong here
kubectl exec runs a command inside the container, so cat /var/log/container.log only works if the application writes to that exact path, which is not guaranteed. Exec suits interactive debugging; kubectl logs reads the container runtime's captured stdout/stderr stream regardless of file paths.
- ✓
kubectl logs my-pod
Why this is correct
`kubectl logs my-pod` retrieves stdout and stderr from the pod's container, satisfying the requirement to view a running pod's logs. It targets the pod by name directly, without needing a pod list, selector or exec session, which is the standard mechanism for reading container output in Kubernetes.
- ✗
kubectl get pod my-pod -o yaml
Why it's wrong here
kubectl get pod my-pod -o yaml returns the pod's manifest and status as YAML, not its container output. It is the right choice for inspecting configuration, resource limits or current state, but retrieving runtime log lines requires kubectl logs, which reads the container's stdout/stderr stream.
- ✗
kubectl describe pod my-pod
Why it's wrong here
kubectl describe pod my-pod aggregates events, conditions and container statuses into a human-readable summary, but it does not return log output. Describe is correct for diagnosing scheduling failures, image pull errors or restarts; viewing the running container's stdout/stderr needs kubectl logs instead.
Go deeper
Related to this question
About these practice questions
Courseiva writes every KCNA question from scratch — 930 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 →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This KCNA 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 KCNA exam.