Question 475 of 997
Kubernetes FundamentalsmediumMultiple ChoiceObjective-mapped

How to view logs of a container inside a pod?

This KCNA practice question tests your understanding of kubernetes fundamentals. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. A key principle to apply: kubectl logs. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

You want to view the logs of a container named 'app' inside a pod named 'web-pod-7d4f8'. Which kubectl command should you use?

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

Option C is correct because the `kubectl logs` command is the standard way to retrieve container logs in Kubernetes. The `-c` flag specifies the container name within the pod, which is necessary when a pod contains multiple containers. Here, the container is named 'app' inside the pod 'web-pod-7d4f8', so `kubectl logs web-pod-7d4f8 -c app` correctly fetches its logs.

Key principle: kubectl logs

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

    Why it's wrong here

    kubectl exec is for running commands inside a container, not for fetching logs.

  • kubectl log web-pod-7d4f8 --container app

    Why it's wrong here

    The command is 'kubectl logs', not 'kubectl log'.

  • kubectl logs web-pod-7d4f8 -c app

    Why this is correct

    This is the correct command to view logs of a specific container in a pod.

    Related concept

    kubectl logs

  • kubectl logs web-pod-7d4f8 app

    Why it's wrong here

    The correct syntax requires the -c flag before the container name: 'kubectl logs web-pod-7d4f8 -c app'.

Common exam traps

Common exam trap: answer the scenario, not the keyword

In the KCNA exam, candidates often confuse 'kubectl logs' with 'kubectl exec' or use incorrect flag syntax (e.g., '--container' vs '-c'). Option C is the only correct syntax because 'kubectl logs' requires the pod name and optionally '-c' for container name.

Trap categories for this question

  • Command / output trap

    kubectl exec is for running commands inside a container, not for fetching logs.

Detailed technical explanation

How to think about this question

Under the hood, `kubectl logs` communicates with the kubelet on the node hosting the pod via the API server, requesting the container's log stream from its log file (typically stored at `/var/log/pods/<namespace>_<pod-name>_<uid>/<container-name>/0.log`). The `-c` flag is essential in multi-container pods because the kubelet needs to identify which container's stdout/stderr stream to retrieve. In real-world scenarios, if you omit `-c` in a multi-container pod, kubectl will return an error prompting you to specify a container name, which is a common pitfall for candidates.

KKey Concepts to Remember

  • kubectl logs
  • -c flag
  • kubectl exec

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

kubectl logs

Real-world example

How this comes up in practice

A practitioner preparing for the KCNA exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. kubectl logs Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Review kubectl logs, then practise related KCNA questions on the same topic to reinforce the concept.

Related practice questions

Related KCNA practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free KCNA practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this KCNA question test?

Kubernetes Fundamentals — This question tests Kubernetes Fundamentals — kubectl logs.

What is the correct answer to this question?

The correct answer is: kubectl logs web-pod-7d4f8 -c app — Option C is correct because the `kubectl logs` command is the standard way to retrieve container logs in Kubernetes. The `-c` flag specifies the container name within the pod, which is necessary when a pod contains multiple containers. Here, the container is named 'app' inside the pod 'web-pod-7d4f8', so `kubectl logs web-pod-7d4f8 -c app` correctly fetches its logs.

What should I do if I get this KCNA question wrong?

Review kubectl logs, then practise related KCNA questions on the same topic to reinforce the concept.

What is the key concept behind this question?

kubectl logs

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More KCNA practice questions

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.