Courseiva
Kubernetes FundamentalshardMultiple ChoiceObjective-mapped

KCNA Kubernetes Fundamentals Practice Question

You have a multi-container pod with containers 'app' and 'sidecar'. You need to execute a shell command inside the 'sidecar' container. Which kubectl command should you use?

⚠ Common exam trap

CNCF often tests the misconception that `kubectl exec` defaults to the first container or that the container flag is optional, leading candidates to pick option A, which would execute in the wrong container.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

kubectl exec -it mypod -c sidecar -- /bin/sh

`kubectl exec` uses the `-c` flag (or `--container`) to specify a target container within a multi-container pod. The syntax `kubectl exec -it mypod -c sidecar -- /bin/sh` opens an interactive shell in the 'sidecar' container of the pod named 'mypod'. Without the `-c` flag, the command defaults to the first container in the pod's spec, which would be 'app'.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • kubectl exec -it mypod -- /bin/sh

    Why it's wrong here

    This execs into the first container by default, not the sidecar.

  • kubectl exec -it sidecar --container mypod -- /bin/sh

    Why it's wrong here

    Incorrect syntax; pod name should come before -c.

  • kubectl exec -it mypod --container sidecar -- /bin/sh

    Why it's wrong here

    The flag is -c, not --container.

  • kubectl exec -it mypod -c sidecar -- /bin/sh

    Why this is correct

    The -c flag specifies the container to exec into.

About these practice questions

This KCNA question is part of Courseiva's 833-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on KCNA

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A Pod has two containers. You need to see the logs of the second container named 'sidecar'. Which kubectl command should you use?

easy
  • A.kubectl logs pod-name --container sidecar
  • B.kubectl logs sidecar pod-name
  • C.kubectl logs pod-name sidecar
  • D.kubectl logs pod-name -c sidecar

Why A: The command `kubectl logs pod-name --container sidecar` (option A) explicitly specifies the sidecar container. While `-c sidecar` is also a valid shorthand, this question expects the command as listed in option A. Both forms achieve the same result, but in this single-choice format, option A is the designated correct answer.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This KCNA practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the KCNA exam.