What flag would you use to fetch logs for a specific container in a pod when using kubectl logs?

Study for the Kubernetes Cloud Native Associate (KCNA) Certification. Prepare with flashcards and multiple choice questions. Ensure success with detailed explanations. Ready for your exam!

Multiple Choice

What flag would you use to fetch logs for a specific container in a pod when using kubectl logs?

Explanation:
When a pod contains more than one container, you must tell kubectl which container’s logs you want. The flag -c <container_name> selects the specific container inside the pod, so kubectl logs <pod-name> -c <container-name> will fetch the logs for that container. If the pod has only one container, you can omit this flag and kubectl will return its logs by default. The other flags don’t target a particular container: -p shows logs from a previously terminated container, -f streams logs in real time, and -l is a label selector to choose which pods to fetch logs from.

When a pod contains more than one container, you must tell kubectl which container’s logs you want. The flag -c selects the specific container inside the pod, so kubectl logs -c will fetch the logs for that container. If the pod has only one container, you can omit this flag and kubectl will return its logs by default.

The other flags don’t target a particular container: -p shows logs from a previously terminated container, -f streams logs in real time, and -l is a label selector to choose which pods to fetch logs from.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy