Bird
0
0

If you run kubectl exec -it mypod -- /bin/sh on a pod with multiple containers, what will happen?

medium📝 Command Output Q5 of 15
Kubernetes - kubectl Essential Commands
If you run kubectl exec -it mypod -- /bin/sh on a pod with multiple containers, what will happen?
Akubectl will execute the command in the first container by default
Bkubectl will return an error asking to specify the container name
Ckubectl will open shells in all containers simultaneously
Dkubectl will ignore the pod and run the command on the node
Step-by-Step Solution
Solution:
  1. Step 1: Understand container selection

    When a pod has multiple containers, kubectl exec requires specifying which container to target using -c.
  2. Step 2: Behavior without container specified

    If container is not specified, kubectl returns an error prompting to choose one.
  3. Final Answer:

    kubectl will return an error asking to specify the container name -> Option B
  4. Quick Check:

    Multiple containers require -c flag [OK]
Quick Trick: Specify container with -c when pod has multiple containers [OK]
Common Mistakes:
  • Assuming default container is chosen automatically
  • Expecting command to run on all containers
  • Ignoring error messages about container selection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes