CKA Workloads and Scheduling Practice Question
You want to ensure that a pod only runs on nodes that have a GPU. Nodes with GPUs are labeled with 'gpu=true'. Which scheduling constraint should you use?
⚠ Common exam trap
Test-takers frequently confuse `nodeSelector` with `nodeAffinity` or `podAffinity`, thinking the more complex option is always better, but the CKA exam tests your ability to choose the simplest correct solution for a given requirement.
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
✓
spec.nodeSelector: { gpu: "true" }
`spec.nodeSelector` is the simplest and most direct way to constrain a pod to nodes with a specific label. By setting `gpu: "true"` in the nodeSelector, the scheduler will only place the pod on nodes that have that exact label key-value pair. This is the standard Kubernetes mechanism for node-level selection based on labels.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
spec.nodeName: gpu-node
Why it's wrong here
Specifying spec.nodeName directly pins the pod to a particular node by its exact hostname, such as "gpu-node", but this is a literal name, not a label key/value. This approach bypasses the scheduler's label-based filtering entirely and will fail if the node name is misspelled, unavailable, or if the intent is to target any node carrying the GPU label. Moreover, it prevents the pod from being rescheduled to another matching node after a failure, making it an inflexible and non-declarative way to express a node-label constraint.
- ✗
spec.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecution
Why it's wrong here
Pod affinity is designed to schedule pods relative to other pods that are already running, such as "co-locate with pods having the label app=web". It does not evaluate node labels directly, so it cannot require that the node itself has the gpu=true label. While you could indirectly approximate this by referencing pods that happen to run on GPU-labeled nodes, that introduces an unnecessary dependency on existing pod placement and is not the intended mechanism for constraining nodes by their own characteristics.
- ✗
spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution
Why it's wrong here
Node affinity with a requiredDuringSchedulingIgnoredDuringExecution rule can technically enforce the same label-based constraint, because it allows matching on node labels using operators like In or Exists. However, for a single exact key-value match such as gpu=true, nodeAffinity requires writing a YAML block under matchExpressions with a rule and a matchFields, which is far more verbose and less readable than a simple nodeSelector map. Since the question asks for a straightforward way to ensure the node label, nodeSelector is the recommended, more idiomatic choice, even though nodeAffinity is not functionally incorrect.
- ✓
spec.nodeSelector: { gpu: "true" }
Why this is correct
The nodeSelector field provides a concise key-value map that the scheduler uses as a hard constraint for node selection. When you set nodeSelector to { gpu: "true" }, the scheduler will only place the pod on nodes that have the label gpu with the exact value "true". This is entirely label-driven, so it works across any number of GPU-enabled nodes, unlike nodeName, and it is the simplest declarative mechanism for an equality-based node label requirement, requiring no nested API structures.
Go deeper
Related to this question
Learn chapter
Kubernetes Architecture Overview
Key term
Ingress Resources
Ingress Resources are Kubernetes API objects that manage external access to services inside a cluster, typically HTTP and HTTPS traffic, by defining rules for routing requests based on hostnames and paths.
Key term
Node Affinity
Node Affinity is a set of rules used by Kubernetes to determine which nodes a pod can be scheduled on, based on labels assigned to the nodes.
About these practice questions
This CKA question is part of Courseiva's 302-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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 CKA 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 CKA exam.