Node Selectors
Node selectors provide a simple way to constrain pods to nodes with specific labels. This is the simplest form of node selection constraint.
How Node Selectors Work
- Label your nodes with descriptive key-value pairs
- Use
nodeSelector
in the pod spec to select nodes with matching labels
Example: Using Node Selectors
First, label your nodes:
kubectl label nodes node1 disk=ssd
kubectl label nodes node2 disk=hdd
Then, create a pod that selects nodes with SSD storage:
apiVersion: v1
kind: Pod
metadata:
name: nginx-ssd
spec:
nodeSelector:
disk: ssd
containers:
- name: nginx
image: nginx
This pod will only be scheduled on nodes with the label disk=ssd
.
Limitations of Node Selectors
Node selectors are simple but limited:
- They use exact matches only (no expressions or soft preferences)
- They don’t support complex logic (such as
OR
conditions, negative matches) - They can’t express preferences (only hard requirements)
For more complex scheduling needs, use node affinity.