Courseiva
Kubernetes Fundamentals →mediumMultiple Choice

KCNA Kubernetes Fundamentals Practice Question

Which command would you use to view the logs of a container named 'web' in a pod named 'frontend' running in the 'production' namespace?

⚠ Common exam trap

CNCF often tests the correct ordering of flags and positional arguments in `kubectl` commands, specifically that the `-c` container flag must come after the pod name, not before, and that omitting it when a pod has multiple containers will not target the intended 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 logs frontend -c web -n production

The `kubectl logs` command requires the pod name as the first positional argument, and the `-c` flag specifies the container name when a pod has multiple containers. The `-n` flag sets the namespace. The correct syntax is `kubectl logs <pod-name> -c <container-name> -n <namespace>`, which matches option B exactly.

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 logs -c web frontend --namespace production

    Why it's wrong here

    The order of arguments is incorrect; pod name should come before -c.

  • ✓

    kubectl logs frontend -c web -n production

    Why this is correct

    `kubectl logs` targets a single container's stdout/stderr stream, and the `-c web` flag selects the container named 'web' within the pod, while `-n production` satisfies the namespace constraint. Without `-c`, the command would fail on a multi-container pod or default to the wrong container.

  • ✗

    kubectl logs frontend -n production container web

    Why it's wrong here

    The container flag is misplaced: kubectl expects -c web or --container=web, so 'container web' is parsed as a second resource argument and the command errors. It is tempting because it mirrors kubectl's flag syntax, yet only the correct -c form selects the container within the pod.

  • ✗

    kubectl logs frontend web --namespace production

    Why it's wrong here

    Supplying two positional arguments, 'frontend web', makes kubectl treat them as separate resources rather than pod and container, producing an error. It is tempting because both names appear, yet container selection requires the -c flag, not a second positional argument.

About these practice questions

This KCNA question is part of Courseiva's 930-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

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.