Courseiva
Kubernetes Fundamentals →easyMultiple Choice

KCNA Kubernetes Fundamentals Practice Question

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

⚠ Common exam trap

It's easy for candidates to assume `kubectl logs` can accept the container name as a positional argument without the `-c` flag, confusing it with `kubectl exec` syntax where the container name can be specified with `-c` but is optional if there's only one 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 web-pod -c nginx

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.

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

    Why this is correct

    The -c flag selects a specific container within a multi-container Pod, so kubectl logs web-pod -c nginx retrieves nginx's logs. This satisfies the stem's constraint of targeting the container named nginx rather than every container in web-pod.

  • ✗

    kubectl logs web-pod nginx

    Why it's wrong here

    kubectl logs takes the container via -c; a bare second argument is parsed as a second pod name, so the command errors. It would be correct as kubectl logs web-pod -c nginx, which is the actual syntax required.

  • ✗

    kubectl describe pod web-pod

    Why it's wrong here

    `kubectl describe pod web-pod` reports the Pod's status, events, and container states, but it does not read the container's stdout/stderr stream, so the nginx application logs never appear. It is tempting because describe is the standard tool for diagnosing scheduling, image-pull, and crash-loop problems — the right choice when you need Pod-level events rather than application output.

  • ✗

    kubectl exec web-pod -- cat /var/log/nginx/access.log

    Why it's wrong here

    Reading a file inside the container shows only what nginx writes to that path, not the container's stdout stream that kubectl logs captures. It would fit inspecting a specific file when the process logs there rather than to stdout.

About these practice questions

One of 930 original KCNA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.