0
0
Kubernetesdevops~20 mins

kubectl exec for container access in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kubectl Exec Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of kubectl exec with command
What is the output of this command if the pod myapp-pod has a container named app-container running a Linux shell?

kubectl exec myapp-pod -c app-container -- ls /tmp
AReturns an error: container app-container not found
BShows the logs of the container app-container
CStarts an interactive shell session inside the container
DLists files and directories inside /tmp of the container
Attempts:
2 left
💡 Hint
The command runs 'ls /tmp' inside the specified container.
💻 Command Output
intermediate
2:00remaining
Error when container name is missing
What error will you get if you run this command on a pod with multiple containers?

kubectl exec mypod -- ls /
AError: a container name must be specified for pod mypod, choose one of: [container1 container2]
BLists root directory contents of the first container automatically
CSyntax error: missing container name
DCommand runs successfully on all containers
Attempts:
2 left
💡 Hint
Pods with multiple containers require specifying which container to exec into.
🔀 Workflow
advanced
2:00remaining
Correct command to start an interactive shell inside a container
Which command correctly starts an interactive bash shell inside the container named web in pod frontend-pod?
Akubectl exec -it frontend-pod -c web -- /bin/bash
Bkubectl exec frontend-pod -c web /bin/bash -i -t
Ckubectl exec frontend-pod -c web --interactive --tty /bin/bash
Dkubectl exec frontend-pod -c web -- bash -it
Attempts:
2 left
💡 Hint
Use -i and -t flags before pod name for interactive terminal.
Troubleshoot
advanced
2:00remaining
Troubleshooting kubectl exec permission denied error
You run kubectl exec mypod -- cat /etc/shadow and get a permission denied error. What is the most likely reason?
AThe pod is not running
Bkubectl exec requires root privileges on the host machine
CThe user inside the container does not have permission to read /etc/shadow
DThe container image does not have /etc/shadow file
Attempts:
2 left
💡 Hint
File /etc/shadow is usually restricted to root user inside Linux.
Best Practice
expert
2:00remaining
Best practice for running commands inside containers with kubectl exec
Which practice is best when using kubectl exec to run commands inside containers in production?
ARun kubectl exec commands as root user inside containers for full access
BAlways specify the container name with -c to avoid ambiguity
CUse kubectl exec without -it flags to avoid interactive sessions
DModify container images to include debugging tools for exec commands
Attempts:
2 left
💡 Hint
Pods often have multiple containers; specifying container avoids mistakes.