CKS runAsNonRoot Practice Question
A pod manifests with securityContext: { runAsNonRoot: true, runAsUser: 1001 }. However, the container image expects to run as root (UID 0). What will happen when the pod is created?
⚠ Common exam trap
The trap is that candidates think `runAsNonRoot` alone blocks execution if the image expects root, but they overlook that `runAsUser` can override the image's user to a non-root UID. In this case, the container runs successfully as user 1001, not fails.
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 container runs as user 1001
When `runAsNonRoot: true` is set, Kubernetes enforces that the container cannot run as root (UID 0). However, the pod also specifies `runAsUser: 1001`, which tells Kubernetes to run the container as UID 1001. Since UID 1001 is non-root, the `runAsNonRoot` constraint is satisfied. The container image's expectation to run as root is irrelevant because Kubernetes overrides the user with the specified `runAsUser`. Therefore, the container will start and run as user 1001.
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 container runs as root because runAsUser overrides runAsNonRoot
Why it's wrong here
This claim is incorrect because runAsNonRoot and runAsUser serve different purposes and do not conflict. runAsNonRoot is a validation constraint that forces the kubelet to reject the container if the effective user is root (UID 0), while runAsUser explicitly sets the user ID to 1001. Since 1001 is non-root, the constraint is satisfied, and the container runs as UID 1001, not root. If runAsUser were 0, the pod would be rejected, not overridden.
- ✗
The container fails to start because it cannot run as root
Why it's wrong here
Incorrect. The container will not fail to start because it is not attempting to run as root. The `runAsUser: 1001` overrides the image's default user, and since 1001 is non-root, the `runAsNonRoot` constraint is satisfied.
- ✓
The container runs as user 1001
Why this is correct
This is the correct behavior. The securityContext.runAsUser field explicitly sets the UID for the container's main process, overriding any USER directive from the image. Because the value is 1001, which is a non-root UID, it concurrently satisfies the runAsNonRoot constraint. The kubelet applies both settings during container startup: runAsUser determines the actual UID, and runAsNonRoot verifies that the resolved UID is not 0, ensuring the container runs as user 1001.
- ✗
The pod runs, but the securityContext is ignored
Why it's wrong here
This is false because the securityContext is fully applied by the kubelet when creating the container. runAsNonRoot triggers a validation check that ensures the effective user is not root, and runAsUser sets the UID to 1001. Had the securityContext been ignored, the container would rely on the image's default user, potentially root, causing runAsNonRoot (if still honored) to fail. Instead, the pod starts successfully, demonstrating that both fields are actively honored and the container runs as UID 1001.
Go deeper
Related to this question
About these practice questions
Courseiva writes every CKS question from scratch — 114 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.