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
This shows container logs, not arbitrary file contents.
- ✗
kubectl cp pod-name:/var/log/app.log -
Why it's wrong here
'kubectl cp' copies files but requires a local destination path.
- ✓
kubectl exec pod-name -- cat /var/log/app.log
Why this is correct
Executes 'cat' inside the container to display the file.
- ✗
kubectl attach pod-name
Why it's wrong here
Attach connects to the container's stdin/stdout, not for viewing files.
Go deeper
Related to this question
About these practice questions
One of 833 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.