Recall & Review
beginner
What does the command
kubectl exec do?It lets you run commands inside a running container in a Kubernetes pod, like opening a terminal session or running a script.
Click to reveal answer
beginner
How do you open an interactive shell inside a container using
kubectl exec?Use
kubectl exec -it <pod-name> -- /bin/sh or /bin/bash to start an interactive shell session.Click to reveal answer
beginner
What does the
-i and -t flags mean in kubectl exec -it?-i keeps the input open (interactive), and -t allocates a terminal, so you can type commands like in a normal shell.Click to reveal answer
intermediate
How do you specify which container to exec into if a pod has multiple containers?
Use the
-c <container-name> option to choose the container inside the pod.Click to reveal answer
beginner
What happens if you run
kubectl exec <pod-name> -- ls /?It runs the
ls / command inside the container, listing the root directory contents without opening an interactive shell.Click to reveal answer
Which command opens an interactive bash shell inside a pod named 'webapp'?
✗ Incorrect
The correct syntax to open an interactive shell is 'kubectl exec -it pod-name -- /bin/bash'.
What does the
-- signify in the command kubectl exec pod -- ls?✗ Incorrect
The double dash
-- tells kubectl that what follows is the command to run inside the container.If a pod has two containers, how do you run a command in the second container?
✗ Incorrect
Use the
-c flag followed by the container name to specify which container to exec into.What is the purpose of the
-t flag in kubectl exec -it?✗ Incorrect
The
-t flag allocates a terminal so you can interact with the shell.Which command lists files in the root directory of a pod named 'db' without opening a shell?
✗ Incorrect
Running 'kubectl exec db -- ls /' executes the command directly inside the container.
Explain how to use
kubectl exec to open an interactive shell inside a container.Think about how to connect to a container like opening a terminal.
You got /5 concepts.
Describe the difference between running a command with
kubectl exec interactively and non-interactively.Consider when you want to type commands versus just get results.
You got /4 concepts.