Recall & Review
beginner
What command is used to execute a command inside a running Kubernetes Pod?
The command
kubectl exec is used to run commands inside a running Pod.Click to reveal answer
beginner
How do you start an interactive shell session inside a Pod named
my-pod?Use
kubectl exec -it my-pod -- /bin/sh or kubectl exec -it my-pod -- /bin/bash to start an interactive shell.Click to reveal answer
beginner
What does the
-it flag mean in kubectl exec?-i means interactive (keeps stdin open), and -t allocates a terminal. Together they allow interactive shell sessions.Click to reveal answer
intermediate
Can you execute commands in a specific container inside a Pod with multiple containers? How?
Yes, use
kubectl exec -it pod-name -c container-name -- command to target a specific container.Click to reveal answer
beginner
What happens if you run
kubectl exec on a Pod that is not running?The command will fail because the Pod must be in a running state to execute commands inside it.
Click to reveal answer
Which command runs an interactive bash shell inside a Pod named 'web-server'?
✗ Incorrect
Option A uses the correct syntax to execute an interactive bash shell inside the Pod.
What does the
-- signify in the command kubectl exec pod-name -- ls?✗ Incorrect
The
-- separates kubectl options from the command to run inside the Pod.How do you specify a container inside a Pod when executing a command?
✗ Incorrect
The
-c flag specifies the container name inside the Pod.If you want to run a non-interactive command like
ls / inside a Pod, which flag is NOT necessary?✗ Incorrect
The
-t flag allocates a terminal and is not needed for non-interactive commands.What will happen if you try to exec into a Pod that is in 'Pending' state?
✗ Incorrect
You cannot exec into a Pod unless it is running.
Explain how to run an interactive shell inside a Kubernetes Pod and why the flags used are important.
Think about how you connect to a remote computer's terminal.
You got /4 concepts.
Describe how to execute a command inside a specific container when a Pod has multiple containers.
Imagine a Pod like a small apartment with multiple rooms (containers).
You got /4 concepts.