Kcna Kubernetes And Cloud Native Associate · Free Practice Question Medium

Question 52

You are a Kubernetes administrator tasked with troubleshooting an issue inside a running pod. What is the most appropriate method to connect to the pod and run commands for debugging?

  • A

    use the kubectl logs command to view the pod's logs and identify the issue without directly connecting to it

  • B

    use kubectl attach to attach to the pod's main process and interact with its terminal

  • C

    create an SSH connection to the worker node where the pod is running and access the pod's file system directly

  • D

    use kubectl exec to connect to it and execute the desired commands

Reveal correct answer

Correct answer: D

Explanation

To connect to a pod for running commands, you can edit the pod's YAML manifest to add a shell container, apply the changes, and then use kubectl exec to establish an interactive shell session inside the pod. This method provides direct access for troubleshooting purposes.

Incorrect Answers:

  • While kubectl attach allows you to attach to a running pod's main process, it doesn't necessarily provide an interactive shell session, and it may not be suitable for running arbitrary commands.

  • Connecting to a worker node and accessing a pod's file system is not a recommended or standard method for interacting with a pod in Kubernetes. It also bypasses Kubernetes' native management capabilities.

  • kubectl logs is used to view the logs of a container within a pod, but it doesn't provide an interactive shell session for running arbitrary commands inside the pod. It's more suitable for log analysis.

https://kubernetes.io/docs/reference/kubectl/cheatsheet/

A. The kubectl logs command is used to view the logs of a pod, which can help in identifying issues without directly connecting to the pod. However, it does not allow for running commands inside the pod for debugging purposes, making it less suitable for troubleshooting specific issues within the pod.

B. The kubectl attach command is used to attach to a running container's main process and interact with its terminal. While this can be useful for monitoring or interacting with the main process, it may not be the most appropriate method for running commands for debugging purposes inside the pod.

C. Creating an SSH connection to the worker node where the pod is running and accessing the pod's file system directly is not a recommended method for debugging inside a running pod. Kubernetes provides kubectl exec specifically for this purpose, and directly accessing the pod's file system through SSH may introduce security risks and is not the standard practice for troubleshooting Kubernetes pods.

D. Using kubectl exec is the most appropriate method to connect to a running pod and execute commands for debugging. This command allows you to run commands inside the pod's container, providing direct access to the pod's environment for troubleshooting purposes.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need