How can you see logs of a particular container from a multi-container pod?

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

How can you see logs of a particular container from a multi-container pod?

Explanation:
To see logs for a specific container inside a pod that runs more than one container, you must tell kubectl which container to show. When a pod has multiple containers, the logs command requires the container to be specified with the -c (or --container) flag. So you run the pod name first, then specify the container you’re interested in, and you’ll get only that container’s logs. For example: kubectl logs <pod_name> -c <container_name>. If you want to continuously stream the logs as they’re written, you can add -f to follow. If you want logs from the previous instance of the container (before it restarted), you can add -p. The other options won’t show the logs for the chosen container: describing the pod doesn’t show the container logs, and placing the container name in the position of the pod name isn’t valid syntax.

To see logs for a specific container inside a pod that runs more than one container, you must tell kubectl which container to show. When a pod has multiple containers, the logs command requires the container to be specified with the -c (or --container) flag. So you run the pod name first, then specify the container you’re interested in, and you’ll get only that container’s logs. For example: kubectl logs -c .

If you want to continuously stream the logs as they’re written, you can add -f to follow. If you want logs from the previous instance of the container (before it restarted), you can add -p. The other options won’t show the logs for the chosen container: describing the pod doesn’t show the container logs, and placing the container name in the position of the pod name isn’t valid syntax.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy