Courseiva

CKAD Application Observability and Maintenance Practice Question

You need to run a command inside a running pod's container. The container has a shell available. Which command allows you to execute 'ls -la /data' inside the container?

⚠ Common exam trap

A common mix-up: candidates confuse `kubectl exec` (which runs a command inside an existing container) with `kubectl run` (which creates a new pod), leading candidates to pick Option B, which would create a new pod instead of executing in the running one.

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 exec pod-name -- ls -la /data

The `kubectl exec` command is designed to execute arbitrary commands inside a running container. The `--` separator tells kubectl that everything after it is the command to run inside the container, not a kubectl flag. Option C correctly uses `kubectl exec pod-name -- ls -la /data` to run `ls -la /data` inside the specified pod's primary 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 exec pod-name

    Why it's wrong here

    The command `kubectl exec pod-name` is incomplete because it omits the required COMMAND argument after the `--` separator. The kubectl exec invocation expects both a pod name and a command to run inside that pod; without a command, the CLI exits with a usage error before contacting the API server. Even though it correctly targets an existing pod, it provides no instruction for the container's process to execute.

  • ✗

    kubectl run pod-name -- ls -la /data

    Why it's wrong here

    The command `kubectl run pod-name -- ls -la /data` does not execute inside an existing pod; instead, it creates a brand-new Pod resource named `pod-name`. If a pod with that name already exists, `kubectl run` fails due to a conflict, and even if it succeeds, the `ls -la /data` runs as the entrypoint of a newly scheduled container, not in the container you intended. This is the standard way to create a one-off pod, not to run a command in a running one.

  • ✓

    kubectl exec pod-name -- ls -la /data

    Why this is correct

    The command `kubectl exec pod-name -- ls -la /data` is correct because it instructs kubectl to run the `ls -la /data` process inside the first container of the existing pod `pod-name`. The `--` separates kubectl's local flags from the remote command to be executed, ensuring that arguments like `-la` are passed to `ls` rather than being interpreted by kubectl. This is the canonical method for executing ad-hoc commands in a running pod's container.

  • ✗

    kubectl attach pod-name -c container-name

    Why it's wrong here

    The command `kubectl attach pod-name -c container-name` does not run a new command; it attaches your terminal's stdin/stdout/stderr to the container's primary process, typically PID 1 (the process defined as the container's entrypoint). Even with the `-c` flag selecting a specific container, attach only connects to an already-running process and cannot invoke an arbitrary command like `ls`. Attach is useful for interacting with a process's live console (e.g., an interactive shell) but not for executing one-off diagnostic commands.

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.