KCNA Kubernetes Fundamentals Practice Question
Which kubectl command is used to see the logs of a container in a pod?
⚠ Common exam trap
Many exam-takers confuse `kubectl logs` with `kubectl exec` for log retrieval, mistakenly thinking that accessing a log file inside the container is the standard approach, when Kubernetes expects logs to be captured from stdout/stderr and accessed via `kubectl logs`.
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>
`kubectl logs <pod-name>` is the dedicated command to retrieve and display the logs from the default container in a specified pod. This command directly accesses the container's stdout and stderr streams, which are captured by the container runtime (e.g., containerd or CRI-O) and stored by the kubelet, making it the standard and simplest way to view application 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 attach <pod-name>
Why it's wrong here
kubectl attach connects an interactive terminal to a running container's process, streaming stdin/stdout rather than retrieving historical log output. It is tempting because attach does surface live console output, so it would be correct when you need to interact with a running process, not when reviewing logs already written.
- ✓
kubectl logs <pod-name>
Why this is correct
kubectl logs retrieves stdout and stderr captured by the kubelet for a container in the named pod, which is the standard mechanism for inspecting application output. Flags such as -c select a specific container in multi-container pods.
- ✗
kubectl exec <pod-name> -- cat /var/log/app.log
Why it's wrong here
`kubectl exec <pod-name> -- cat /var/log/app.log` fails because it requires you to know the exact file path and assumes the container has a shell and `cat` installed, whereas `kubectl logs` streams the container’s stdout/stderr directly without needing filesystem access. It is tempting because `exec` is commonly used to run arbitrary commands inside a container, and in a scenario where the application writes logs only to a file (not stdout), this command would be the correct choice to retrieve them.
- ✗
kubectl describe pod <pod-name>
Why it's wrong here
kubectl describe pod returns pod metadata, events and container status, not stdout or stderr output. It is tempting because describe is the go-to command for diagnosing why a pod is failing, so it would be correct when investigating scheduling, image-pull or readiness-probe problems rather than reading application log lines.
Go deeper
Related to this question
About these practice questions
One of 930 original KCNA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on KCNA
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. You want to view the logs of a running pod named 'my-pod'. Which kubectl command should you use?
easy- A.kubectl exec my-pod -- cat /var/log/container.log
- ✓ B.kubectl logs my-pod
- C.kubectl get pod my-pod -o yaml
- D.kubectl describe pod my-pod
Why B: 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.
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.