In Kubernetes, what is the primary purpose of using a nodeSelector in a Pod specification?
Think about how Kubernetes decides where to place Pods based on node labels.
A nodeSelector is a simple way to constrain Pods to run only on nodes with specific labels. It filters nodes during scheduling.
You have a Pod with the following nodeSelector:
nodeSelector: disktype: ssd
After applying this Pod manifest, what will kubectl get pods -o wide show in the NODE column?
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: nginx
image: nginx
nodeSelector:
disktype: ssdCheck how nodeSelector affects Pod scheduling and node assignment.
The Pod will be scheduled only on nodes labeled with 'disktype=ssd', so the NODE column shows such a node's name.
Which of the following Pod YAML snippets correctly uses nodeSelector to schedule the Pod on nodes labeled zone: us-east-1?
Remember that nodeSelector expects a map of key-value pairs with string values.
Option B correctly uses a string value for the label. Option B misses quotes but is valid YAML; however, quotes are recommended for clarity. Option B uses a list which is invalid. Option B uses a list as value which is invalid.
You created a Pod with this nodeSelector:
nodeSelector: gpu: "true"
The Pod remains in Pending state indefinitely. What is the most likely cause?
Check if any node matches the nodeSelector labels.
If no node has the label gpu=true, the scheduler cannot place the Pod, so it stays Pending.
You manage a Kubernetes cluster shared by multiple teams and environments. Which approach is best to use nodeSelector for simple scheduling to isolate workloads by environment?
Think about how nodeSelector matches node labels, not Pod labels.
NodeSelector matches node labels, so labeling nodes by environment and using nodeSelector in Pods to match those labels is a simple and effective isolation method.