CKA CKA Logging and Monitoring 1 — Questions and Answers
Question 1: How do you view logs from a running pod named 'webapp'?
- kubectl logs webapp (Correct answer)
- kubectl get logs webapp
- kubectl describe logs webapp
- kubectl show logs webapp
Correct answer: kubectl logs webapp
Use `kubectl logs <pod-name>` to retrieve logs from a running pod.
Question 2: Which flag streams live log output continuously from a pod?
- --stream
- --follow (Correct answer)
- --live
- --tail
Correct answer: --follow
The `--follow` (or `-f`) flag streams live log output from a pod, similar to `tail -f`.
Question 3: How do you view logs from a specific container 'nginx' inside a multi-container pod 'mypod'?
- kubectl logs mypod --pod=nginx
- kubectl logs mypod -c nginx (Correct answer)
- kubectl logs mypod --name=nginx
- kubectl logs nginx mypod
Correct answer: kubectl logs mypod -c nginx
The `-c <container-name>` (or `--container`) flag targets a specific container in a multi-container pod.
Question 4: How do you retrieve logs from a previously crashed/terminated container in a pod?
- kubectl logs mypod --restart
- kubectl logs mypod --previous (Correct answer)
- kubectl logs mypod --last
- kubectl logs mypod --crashed
Correct answer: kubectl logs mypod --previous
The `--previous` flag retrieves logs from the last terminated container instance in a pod.
Question 5: Where does Kubernetes store container log files on the node by default?
- /etc/kubernetes/logs/
- /var/log/containers/ (Correct answer)
- /tmp/kubernetes/logs/
- /run/kubernetes/logs/
Correct answer: /var/log/containers/
Container logs are written to `/var/log/containers/` on the node, symlinked from `/var/log/pods/`.
Question 6: Which command displays only the last 50 lines of logs from pod 'api'?
- kubectl logs api --lines=50
- kubectl logs api --tail=50 (Correct answer)
- kubectl logs api --last=50
- kubectl logs api -n 50
Correct answer: kubectl logs api --tail=50
The `--tail=<N>` flag limits log output to the last N lines, mirroring the Unix `tail` command.
How do you view logs from a running pod named 'webapp'?