KCNA Kubernetes Fundamentals Practice Question
A pod is running but you need to view the contents of a file '/var/log/app.log' inside the container to debug an issue. Which kubectl command allows you to do this without modifying the pod?
⚠ Common exam trap
Many exam-takers confuse `kubectl logs` with reading arbitrary files, assuming it can retrieve any log file, when in fact it only captures container stdout/stderr streams, while `kubectl exec` is the correct tool for accessing files inside a container.
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 exec pod-name -- cat /var/log/app.log
`kubectl exec pod-name -- cat /var/log/app.log` runs the `cat` command inside the container without modifying the pod or its state. This allows you to view the file contents directly from the container's filesystem, which is essential for debugging when the application logs are not written to stdout/stderr and thus not accessible via `kubectl 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 logs pod-name -c container-name --tail=100
Why it's wrong here
kubectl logs reads the container's stdout stream, so it only shows output already written there, not an arbitrary file such as /var/log/app.log. It is tempting as the standard debugging command, and would be correct when the application writes its logs to stdout.
- ✗
kubectl cp pod-name:/var/log/app.log -
Why it's wrong here
kubectl cp transfers the file out of the container to the local filesystem; it does not display contents in the terminal. It is tempting because it retrieves the file without exec, and would be correct when the log must be archived or analysed locally with other tools.
- ✓
kubectl exec pod-name -- cat /var/log/app.log
Why this is correct
`kubectl exec` opens a stream into the already-running container's namespace, so `cat` reads `/var/log/app.log` from the container's own filesystem without restarting or altering the pod. This satisfies the stem's constraint of inspecting a live container's file contents non-destructively, unlike `logs`, `cp`, or `describe`.
- ✗
kubectl attach pod-name
Why it's wrong here
kubectl attach connects to the running process's standard input and output, not to files inside the container, so it cannot display /var/log/app.log. It is tempting for interactive debugging, and would be correct when you need to interact with a process already attached to a terminal.
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 →
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.