Challenge - 5 Problems
Kubectl Exec Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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 /tmpAttempts:
2 left
💡 Hint
The command runs 'ls /tmp' inside the specified container.
✗ Incorrect
The 'kubectl exec' command runs the given command inside the container. Here, it lists the contents of /tmp directory inside the container named 'app-container'.
💻 Command Output
intermediate2: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 /Attempts:
2 left
💡 Hint
Pods with multiple containers require specifying which container to exec into.
✗ Incorrect
When a pod has multiple containers, kubectl requires the container name to be specified with -c or --container. Otherwise, it returns an error asking to specify the container.
🔀 Workflow
advanced2: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?
Attempts:
2 left
💡 Hint
Use -i and -t flags before pod name for interactive terminal.
✗ Incorrect
The correct syntax is 'kubectl exec -it podname -c containername -- command'. Flags -i and -t enable interactive terminal. The command follows after '--'.
❓ Troubleshoot
advanced2: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?Attempts:
2 left
💡 Hint
File /etc/shadow is usually restricted to root user inside Linux.
✗ Incorrect
The /etc/shadow file contains sensitive password info and is readable only by root or privileged users inside the container. Permission denied means the current user lacks rights.
✅ Best Practice
expert2: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?Attempts:
2 left
💡 Hint
Pods often have multiple containers; specifying container avoids mistakes.
✗ Incorrect
Specifying the container name with -c ensures the command runs in the intended container, preventing errors or unintended effects. Running as root or modifying images can cause security risks.