Courseiva

CKS Monitoring, Logging and Runtime Security Practice Question

Which kubectl command(s) can you use to view the logs of a specific container in a multi-container pod? (Select all that apply)

⚠ Common exam trap

CKS often tests kubectl command syntax; candidates might think positional arguments work for container names, but only flags are valid.

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 <pod> -c <container>

The `kubectl logs` command supports both `-c` and `--container` flags to specify a container name in a multi-container pod. Both are equivalent and valid. The other options are either incorrect syntax or would display logs from all containers, which does not target a specific container.

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 <pod> -c <container>

    Why this is correct

    The `-c` flag is the shorthand for `--container` and tells kubectl which container's logs to read from the pod. This is essential when the pod runs multiple containers, because kubectl logs by default only returns logs from the first container or fails with an ambiguity error. Both `-c` and `--container` are valid, so this command correctly targets a specific container.

  • ✓

    kubectl logs <pod> --container <container>

    Why this is correct

    The long form `--container` is explicit and improves script readability, exactly matching the container name defined in the pod spec. This flag specifies the container name as a key/value pair, avoiding any ambiguity when multiple containers share the pod's lifecycle. It is the same behavior as `-c` and is equally correct for retrieving a single container's logs.

  • ✗

    kubectl logs <pod> <container>

    Why it's wrong here

    In `kubectl logs <pod> <container>`, the third argument is parsed as another resource name, not a container selector. The kubectl CLI expects only the pod name as the positional argument; the container must be passed with `-c` or `--container=`. As a result, this command either attempts to find a nonexistent resource or fails with a positional-argument error.

  • ✗

    kubectl logs <pod> --all-containers

    Why it's wrong here

    The `--all-containers` flag intentionally fetches logs from every container in the pod and prefixes each line with the container name. That is the opposite of selecting a single container, and it is not a legal way to isolate one container's logs. This option would not answer the request to view logs of a specific container.

About these practice questions

One of 845 original CKS 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 and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official CNCF exam blueprint

This CKS 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 CKS exam.