Which command would you use to view the logs of a container that has crashed and restarted?

Prepare for the KCNA Certification Test. Study with flashcards, multiple-choice questions, and detailed explanations to enhance your understanding of Kubernetes Cloud Native concepts. Ace your exam!

Multiple Choice

Which command would you use to view the logs of a container that has crashed and restarted?

Explanation:
When a container in a pod crashes and restarts, you often need the logs from the prior instance to diagnose the failure. The -p flag (short for --previous) asks kubectl to show the logs from the previously terminated container, not the currently running one. If a pod contains more than one container, you must specify which container you want with -c <container_name>; otherwise kubectl wouldn’t know which container’s logs to display. Putting these together, the command to fetch the logs from the crashed, previous instance of a specific container in a pod is: kubectl logs pod/<pod_name> -c <container_name> -p. If the pod has a single container, you can omit -c, but when there are multiple containers, specifying the container is essential to see the right logs.

When a container in a pod crashes and restarts, you often need the logs from the prior instance to diagnose the failure. The -p flag (short for --previous) asks kubectl to show the logs from the previously terminated container, not the currently running one.

If a pod contains more than one container, you must specify which container you want with -c ; otherwise kubectl wouldn’t know which container’s logs to display. Putting these together, the command to fetch the logs from the crashed, previous instance of a specific container in a pod is: kubectl logs pod/ -c -p.

If the pod has a single container, you can omit -c, but when there are multiple containers, specifying the container is essential to see the right logs.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy