KCNA kubectl logs Practice Question
You want to view the logs of a container named 'app' inside a pod named 'web-pod-7d4f8'. Which kubectl command should you use?
⚠ Common exam trap
In the KCNA exam, candidates often confuse 'kubectl logs' with 'kubectl exec' or use incorrect flag syntax (e.g., '--container' vs '-c'). Option C is the only correct syntax because 'kubectl logs' requires the pod name and optionally '-c' for container name.
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-7d4f8 -c app
The `kubectl logs` command is the standard way to retrieve container logs in Kubernetes. The `-c` flag specifies the container name within the pod, which is necessary when a pod contains multiple containers. Here, the container is named 'app' inside the pod 'web-pod-7d4f8', so `kubectl logs web-pod-7d4f8 -c app` correctly fetches its 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 exec web-pod-7d4f8 -c app -- logs
Why it's wrong here
kubectl exec runs a command inside the container, so '-- logs' would attempt to execute a binary named logs rather than read the container's log stream. It is tempting because exec is the correct choice when you need an interactive shell or to run a diagnostic command within a running container.
- ✗
kubectl log web-pod-7d4f8 --container app
Why it's wrong here
The subcommand is 'logs', not 'log'; kubectl has no 'log' verb, so the command fails before contacting the API server. It is tempting because the singular form reads naturally and the flags are otherwise structured correctly, which is the right shape once the verb is spelled 'logs'.
- ✓
kubectl logs web-pod-7d4f8 -c app
Why this is correct
kubectl logs retrieves stdout/stderr from a single container, and the -c flag selects which container when a pod holds several. Naming web-pod-7d4f8 with -c app satisfies the stem's requirement to target the container named 'app'.
- ✗
kubectl logs web-pod-7d4f8 app
Why it's wrong here
Positional arguments after the pod name are treated as the command to execute, not as a container selector; the container must be named with --container or -c. It is tempting because passing the container name positionally mirrors how some other CLIs accept arguments, but kubectl requires the explicit flag.
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.