Node Affinity and Taints/Tolerations
Node Affinity allows you to constrain which nodes your pod is eligible to be scheduled on, based on node labels.
Types of Affinity:
- RequiredDuringSchedulingIgnoredDuringExecution: Mandatory rules
- PreferredDuringSchedulingIgnoredDuringExecution: Preferred but not enforced
Example Node Affinity:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: disktype
operator: In
values:
- ssd
Taints and Tolerations:
- Taints: Applied to nodes to repel pods
- Tolerations: Added to pods to allow scheduling on tainted nodes
Example:
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
Taints and tolerations are powerful for workload isolation, while affinity helps with scheduling strategy and optimization.