CKS Monitoring, Logging and Runtime Security Practice Question
You need to preserve evidence (container logs) from a compromised pod before deleting it. Which command should you run first?
⚠ Common exam trap
The CKS exam often tests the misconception that `kubectl cp` or `kubectl exec` can reliably retrieve container logs, but in Kubernetes, stdout/stderr logs are not stored as regular files inside the container's filesystem, so only `kubectl logs` can capture them before pod deletion.
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> --tail=-1 > pod.log
`kubectl logs --tail=-1` retrieves the complete log history (all lines) from the container's stdout/stderr stream, which is the primary source of container logs in Kubernetes. Redirecting this output to a file preserves the evidence before the pod is deleted, ensuring the logs are not lost when the pod is removed.
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 <pod> -- cat /var/log/*
Why it's wrong here
Reading log files inside the container via exec alters the running filesystem and captures only files present at that path, not the container's stdout log stream, contaminating evidence. It is tempting because exec gives direct shell access to a live pod, which is useful for interactive inspection when preservation is not the priority.
- ✗
kubectl cp <pod>:/var/log ./pod-logs
Why it's wrong here
Copying files from the container's filesystem does not retrieve the container's stdout/stderr log stream that kubectl logs exposes, so the actual evidence is missed. It is tempting because kubectl cp is the standard way to extract files from a pod, which is right when the evidence is a file rather than the log stream.
- ✓
kubectl logs <pod> --tail=-1 > pod.log
Why this is correct
Capturing the full log stream before deletion preserves volatile evidence that vanishes with the pod. The --tail=-1 flag retrieves every retained line rather than the default last ten, satisfying the requirement to secure container logs prior to removing the compromised workload.
- ✗
kubectl delete pod <pod>
Why it's wrong here
Deleting the pod destroys the container filesystem and its logs before any evidence is captured, so the data is unrecoverable. It is tempting because deletion is the eventual cleanup step, and would be correct only after logs have been copied out with kubectl logs or a similar capture command.
Go deeper
Related to this question
About these practice questions
This CKS question is part of Courseiva's 845-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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 CKS 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 CKS exam.