Courseiva

CKS Monitoring, Logging and Runtime Security Practice Question

You run 'kubectl exec -it <pod> -- /bin/sh' inside a pod that has an immutable root filesystem. What happens?

⚠ Common exam trap

CKS often tests the misconception that 'exec' provides privileged access that bypasses securityContext restrictions, when in fact it operates within the same constraints.

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

✓

The shell starts successfully, but any attempt to write to the root filesystem will be denied

When a container has an immutable root filesystem (e.g., readOnlyRootFilesystem: true in Kubernetes), the root filesystem is mounted as read-only. Running 'kubectl exec' to start a shell will succeed because the shell binary is already present and executable. However, any attempt to write to the root filesystem (e.g., creating a file) will be denied with a 'Read-only file system' error. The shell itself does not bypass the restriction.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    The command fails with an error because the container has an immutable root filesystem

    Why it's wrong here

    The readOnlyRootFilesystem field only makes the container's root mount read-only; it does not prevent the runtime from launching a process. The kubectl exec command delegates to the container runtime's exec handler, which locates the requested binary in the container's writable layer or mounted filesystem and executes it. An immutable root filesystem would only cause failure if the shell binary itself were missing or could not be executed, not because the filesystem is read-only.

  • ✗

    The shell starts and can write to any directory because 'exec' bypasses the restriction

    Why it's wrong here

    The container runtime enforces the read-only root mount for every process within the container's mount namespace, including those spawned by exec. When you exec into a container, the new process joins the same mount and PID namespace and thus sees the same root filesystem mounted with the same flags. The exec channel only transmits stdin/stdout/stderr and the command; it cannot lift kernel-mandated mount restrictions, so any write attempt outside explicitly mounted writable volumes is still denied.

  • ✓

    The shell starts successfully, but any attempt to write to the root filesystem will be denied

    Why this is correct

    A successful kubectl exec starts a shell only if the container image contains that shell binary; the readOnlyRootFilesystem flag does not block process creation. Once the shell is running, it inherits the container's read-only root mount, meaning operations like touch /file or redirecting output to /root/out.txt will fail with a read-only file system error. Only paths backed by writable volumes defined in the pod spec, such as emptyDir or a mounted persistent volume, will accept writes.

  • ✗

    The pod is restarted with a writable filesystem

    Why it's wrong here

    Exec does not trigger a Pod lifecycle change; it injects an ephemeral process into an existing container. The Pod's securityContext is fixed at creation time, and the kubelet does not recreate the Pod merely because a user runs kubectl exec. To change readOnlyRootFilesystem, you must edit the Pod's securityContext and recreate the Pod, which would be a separate explicit operation rather than an automatic restart.

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.