Certified Kubernetes Application Developer (CKAD) Practice Test

Disable ads (and more) with a membership for a one time $4.99 payment

Enhance your skills for the CKAD exam. Study with curated quizzes and detailed explanations. Prepare effectively for your success!

Practice this question and more.


Which command allows you to run a command inside a container/pod?

  1. kubectl run <pod_name> -- <command>

  2. kubectl exec -it <pod_name> -- <command>

  3. kubectl attach <pod_name> -- <command>

  4. kubectl create pod <pod_name> -- <command>

The correct answer is: kubectl exec -it <pod_name> -- <command>

The command that allows you to run a command inside a container in a pod is accomplished using `kubectl exec -it <pod_name> -- <command>`. This command is specifically designed to execute commands directly inside the container of a running pod. When using `kubectl exec`, the `-it` flags make the session interactive, allowing for real-time interaction with the command executed inside the container. The `--` is used to signify that any subsequent arguments should be treated as commands to be executed in the container, rather than interpreted as options for `kubectl`. This command is especially useful for debugging purposes, as it allows you to interact with the shell or execute specific commands in a live container without needing to modify the running configuration of your application. Other commands, while they may seem related, serve different purposes. For instance, `kubectl run` is primarily used to create and run a new pod but isn't suitable for executing commands in an existing one. Similarly, `kubectl attach` is intended for attaching to a process running in a container, but it does not initiate a command in the way that `exec` does. The command `kubectl create pod` is used for defining the pod specifications and creating new pods,