Courseiva

CKAD Application Observability and Maintenance Practice Question

You need to view the logs of a container named 'sidecar' inside a pod named 'app'. Which command should you use?

⚠ Common exam trap

The trap here is that candidates often forget the `-c` flag for multi-container pods and assume the container name can be passed as a positional argument, leading them to choose option C.

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 app -c sidecar

`kubectl logs app -c sidecar` explicitly targets the 'sidecar' container within the 'app' pod. In Kubernetes, when a pod runs multiple containers, you must use the `-c` flag to specify which container's logs to retrieve; otherwise, the command fails or returns ambiguous output.

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 app -c sidecar

    Why this is correct

    The command `kubectl logs app -c sidecar` is correct because it explicitly targets the `sidecar` container within the `app` pod using the `-c` flag. This is the required syntax for retrieving logs from a specific container in a multi-container pod. Without the `-c` flag, kubectl would either fail or default to the first container, so this option precisely fetches the current logs of the desired container.

  • ✗

    kubectl logs app --previous -c sidecar

    Why it's wrong here

    Using `--previous` changes the query to fetch logs from an earlier incarnation of the `sidecar` container (e.g., after a restart or crash), not the live process. This is useful for post-mortem debugging, but it does not satisfy the requirement of viewing the current logs. The presence of `-c sidecar` is fine, but the `--previous` flag redirects the output to historical logs, making this option incorrect for the stated task.

  • ✗

    kubectl logs app sidecar

    Why it's wrong here

    The syntax `kubectl logs app sidecar` treats `sidecar` as an extra positional argument, which is not valid — kubectl logs accepts at most one argument, the pod name. To select a container, you must use the `-c` flag; passing the container name directly as a second argument will cause an error such as 'expected exactly one argument'. Thus, this command is malformed and will not show any logs.

  • ✗

    kubectl logs app -c sidecar -p

    Why it's wrong here

    The `-p` flag is the short form of `--previous`, so even though `-c sidecar` correctly identifies the container, the `-p` switches the scope to the previous instance of that container. This is equivalent to the `--previous` variant and equally fails to show the current logs. The ordering of flags is irrelevant; the presence of `-p` makes it historical, not live.

About these practice questions

One of 826 original CKAD 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 CKAD 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 CKAD exam.