0
0
Kubernetesdevops~20 mins

Executing commands in Pods in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pod Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of command executed inside a Pod
You run the command kubectl exec mypod -- ls /app on a Pod named mypod. The Pod's /app directory contains files index.html and config.yaml. What will be the output?
A
index.html
config.yaml
B
mypod
index.html
config.yaml
CError: directory not found
DNo resources found.
Attempts:
2 left
💡 Hint
The kubectl exec command runs the given command inside the Pod's container.
🧠 Conceptual
intermediate
1:30remaining
Understanding kubectl exec command syntax
Which of the following is the correct syntax to execute the command cat /etc/hosts inside a Pod named webserver?
Akubectl exec --webserver cat /etc/hosts
Bkubectl exec webserver -- cat /etc/hosts
Ckubectl exec webserver cat /etc/hosts
Dkubectl exec -- pod=webserver -- cat /etc/hosts
Attempts:
2 left
💡 Hint
The Pod name comes immediately after kubectl exec, followed by -- to separate the command.
Troubleshoot
advanced
2:00remaining
Troubleshooting kubectl exec permission error
You try to run kubectl exec mypod -- whoami but get the error: error: unable to upgrade connection: Forbidden. What is the most likely cause?
AThe Kubernetes API server is down
BThe Pod does not exist
CThe command <code>whoami</code> is not installed in the Pod
DThe user running kubectl lacks permission to exec into the Pod
Attempts:
2 left
💡 Hint
The error mentions 'Forbidden', which relates to permissions.
🔀 Workflow
advanced
2:00remaining
Executing an interactive shell inside a Pod
You want to open an interactive bash shell inside a Pod named backend. Which command should you use?
Akubectl exec -it backend -- /bin/bash
Bkubectl exec backend /bin/bash -i
Ckubectl exec backend --interactive /bin/bash
Dkubectl exec backend -bash -it
Attempts:
2 left
💡 Hint
Use flags -i and -t for interactive terminal.
Best Practice
expert
2:30remaining
Best practice for running commands in multi-container Pods
A Pod has two containers: app and sidecar. You want to run ls /data inside the sidecar container. Which command is correct?
Akubectl exec mypod --container sidecar ls /data
Bkubectl exec mypod --container sidecar -- ls /data
Ckubectl exec mypod -c sidecar -- ls /data
Dkubectl exec mypod --container=sidecar ls /data
Attempts:
2 left
💡 Hint
Use -c or --container with kubectl exec to specify container.