0
0
Kubernetesdevops~5 mins

Executing commands in Pods in Kubernetes - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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'?
Akubectl exec -it web-server -- /bin/bash
Bkubectl run web-server -- /bin/bash
Ckubectl start web-server -bash
Dkubectl shell web-server
What does the -- signify in the command kubectl exec pod-name -- ls?
AEnds the command execution
BSeparates kubectl flags from the command to run inside the Pod
CSpecifies the Pod namespace
DIndicates the Pod name
How do you specify a container inside a Pod when executing a command?
A--container container-name
B-p container-name
C-c container-name
D-n container-name
If you want to run a non-interactive command like ls / inside a Pod, which flag is NOT necessary?
A-c
B-i
C--
D-t
What will happen if you try to exec into a Pod that is in 'Pending' state?
AThe command will fail because the Pod is not running
BYou will get a shell prompt
CThe Pod will start automatically
Dkubectl will restart the Pod
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.