Courseiva
Kubernetes FundamentalseasyMultiple ChoiceObjective-mapped

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 specifies the container name when there are multiple containers.

  • kubectl logs web-pod nginx

    Why it's wrong here

    The syntax 'kubectl logs <pod> <container>' is not valid; the container name must be specified with -c.

  • kubectl describe pod web-pod

    Why it's wrong here

    Describe shows details about the pod but not logs.

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

    Why it's wrong here

    This command execs into the container and reads a log file, but it's not the standard way to view container logs; kubectl logs is preferred.

About these practice questions

One of 833 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.