Courseiva
Kubernetes FundamentalsmediumMultiple ChoiceObjective-mapped

KCNA Kubernetes Fundamentals Practice Question

Which kubectl command would you use to view the logs of a specific container named 'app' in a multi-container Pod named 'web-pod'?

⚠ Common exam trap

The trap here is that candidates often forget the `-c` flag and assume `kubectl logs web-pod app` works by positional arguments, but Kubernetes requires the explicit `-c` flag for multi-container Pods.

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 web-pod -c app

The `kubectl logs` command uses the `-c` flag to specify a container name within a multi-container Pod. The correct syntax is `kubectl logs <pod-name> -c <container-name>`, which targets the 'app' container inside 'web-pod'.

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 log web-pod container app

    Why it's wrong here

    There is no 'kubectl log' command; it is 'kubectl logs'.

  • kubectl logs web-pod app

    Why it's wrong here

    The correct syntax is 'kubectl logs pod-name -c container-name'.

  • kubectl logs web-pod -c app

    Why this is correct

    The -c flag specifies the container name in a multi-container Pod.

  • kubectl logs app web-pod

    Why it's wrong here

    Order is incorrect; the Pod name comes first.

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

2 more ways 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. Which command would you use to view the logs of a container named 'nginx' in a Pod named 'web-pod'?

easy
  • A.kubectl logs web-pod -c nginx
  • B.kubectl logs web-pod nginx
  • C.kubectl describe pod web-pod
  • D.kubectl exec web-pod -- cat /var/log/nginx/access.log

Why A: The `kubectl logs` command retrieves container logs from a Pod, and when a Pod contains multiple containers, the `-c` flag is required to specify which container's logs to view. Here, `kubectl logs web-pod -c nginx` explicitly targets the 'nginx' container within the 'web-pod' Pod, which is the standard Kubernetes API approach for fetching container stdout/stderr streams.

Variation 2. Which command would you use to view the logs of a container named 'sidecar' inside a pod named 'app'?

medium
  • A.kubectl logs app -c sidecar
  • B.kubectl logs app sidecar
  • C.kubectl logs sidecar app
  • D.kubectl logs sidecar -p app

Why A: The `kubectl logs` command uses the `-c` flag to specify a container name within a pod. When a pod contains multiple containers, you must explicitly indicate which container's logs to retrieve. The syntax `kubectl logs <pod-name> -c <container-name>` is the standard way to view logs from a specific container in a multi-container pod.

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.