Certified Kubernetes Administrator (CKA) Practice Test

1 / 400

How do you access a Pod's shell in Kubernetes?

By using kubectl attach <pod-name>

By using kubectl exec -it <pod-name> -- /bin/bash

By using kubectl exec -it <pod-name> -- /bin/sh

To access a Pod's shell in Kubernetes, using the command with `kubectl exec -it <pod-name> -- /bin/sh` is a correct approach, particularly because it is often applicable to containers that use lightweight images, such as Alpine, which may not include bash but do have sh available.

The use of `kubectl exec` allows you to execute commands directly in the context of a specific container within a pod. The `-it` flag enables interactive mode and allocates a pseudo-TTY, which means you can interact with the shell as if you were directly logged into a terminal.

Using `/bin/sh` ensures compatibility with a broader range of container images, especially those that do not have `/bin/bash`, thus making this method widely applicable for shell access in various container environments.

While `kubectl exec -it <pod-name> -- /bin/bash` could also provide shell access if the container has bash installed, it's worth noting that not all containers will have this populated, and therefore, the more universal option is `/bin/sh`.

Get further explanation with Examzify DeepDiveBeta

By accessing the Kubernetes dashboard

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy