
Explanation:
The correct approach is option C, as the kubectl exec command is designed to execute commands in a container within a Pod, including starting an interactive shell. This method is particularly useful for troubleshooting by allowing direct interaction with the container's environment. The syntax kubectl exec -it [POD_NAME] -- /bin/bash opens a bash shell in the specified Pod, enabling the execution of diagnostic commands. If the Pod contains multiple containers, the -c [CONTAINER_NAME] option can specify the target container. This capability is essential for debugging issues that are not reproducible in other environments.
Ultimate access to all questions.
You’ve identified errors in the logs for a specific Deployment, pinpointing the issue to the Pod named 'ad-generator'. Your team cannot replicate the error in other environments and believes that accessing the container directly for a brief period would help diagnose the root cause. What action should they take to run commands inside the container?
A
Execute the command kubectl run ad-generator /bin/bash to initiate a shell session within the container.
B
Use the command kubectl exec -it -- /bin/bash to start a shell session on the container.
C
Initiate a shell session on the container by running kubectl exec -it ad-generator -- /bin/bash.
D
Launch a shell session on the container with the command kubectl run.
No comments yet.