CKAD · Question #7
You sometimes need to observe a pod's logs, and write those logs to a file for further analysis. Please complete the following; Deploy the counter_pod to the cluster using the provided YAMLspec file…
This question tests your ability to deploy a Kubernetes pod from a YAML manifest and capture its logs to a file using kubectl. It covers two fundamental kubectl operations: apply and logs.
Question
- Deploy the counter_pod to the cluster using the provided YAMLspec file at /opt/KDOB00201/counter.yaml
- Retrieve all currently available application logs from the running pod and store them in the file /opt/KDOB00201/log_Output.txt, which has already been created
Explanation
This question tests your ability to deploy a Kubernetes pod from a YAML manifest and capture its logs to a file using kubectl. It covers two fundamental kubectl operations: apply and logs.
Approach. Step 1 - deploy the pod: kubectl apply -f /opt/KDOB00201/counter.yaml. Wait for it to reach Running state with kubectl get pod counter or kubectl get pods. Step 2 - retrieve and store logs: kubectl logs counter > /opt/KDOB00201/log_Output.txt. The > redirect writes stdout (the log output) into the already-created file. If the pod has multiple containers you would need to add -c <container-name>, but for a simple counter pod a single container is assumed. Do NOT use kubectl logs -f (follow/stream mode) - the question asks for currently available logs, not a live stream, so omit the -f flag to avoid the command hanging indefinitely.
Concept tested. kubectl apply (declarative pod deployment from a YAML manifest) and kubectl logs (retrieving pod stdout/stderr), combined with shell output redirection to persist logs to a file.
Reference. https://kubernetes.io/docs/reference/kubectl/generated/kubectl_logs/
Topics
Community Discussion
No community discussion yet for this question.