You can combine taints and tolerations with node affinity to schedule pods on specific nodes. Apply taints and tolerations to your nodes first to prevent other pods from being scheduled on them, then use node affinity to prevent your pods from being scheduled on other nodes.
Concept and usage
Node affinity allows you to specify rules for placing pods on specific nodes. For example, you can schedule a pod only on nodes that have a large or medium GPU.sample-pod.yaml
The
Exists operator checks whether a label key exists on the node. When using Exists, you do not need to specify the values field — it does not compare values.Node affinity types
Node affinity types are composed of two phases: DuringScheduling and DuringExecution.DuringScheduling
DuringScheduling
Applies when the pod does not yet exist on the node — the rules must be met for the pod to be scheduled.
requiredDuringScheduling— The pod must be scheduled on a node that satisfies the rule.preferredDuringScheduling— The pod is scheduled on a satisfying node if possible. If no such node exists, the pod is scheduled elsewhere.
DuringExecution
DuringExecution
Applies when the pod is already running on the node. Determines what happens if node labels change after scheduling.
RequiredDuringExecution— The pod is evicted if the node label changes and the rule is no longer satisfied.IgnoredDuringExecution— The pod continues to run even if the node label changes.
Available affinity types
requiredDuringSchedulingIgnoredDuringExecution
requiredDuringSchedulingIgnoredDuringExecution
The pod must be scheduled on a node that satisfies the rule. If no node satisfies the rule, the pod is not scheduled. If node labels change after scheduling, the pod continues to run.
preferredDuringSchedulingIgnoredDuringExecution
preferredDuringSchedulingIgnoredDuringExecution
The pod is scheduled on a satisfying node if possible. If no node satisfies the rule, the pod is scheduled on another node. If node labels change after scheduling, the pod continues to run.
requiredDuringSchedulingRequiredDuringExecution
requiredDuringSchedulingRequiredDuringExecution
The pod must be scheduled on a node that satisfies the rule. If node labels change after scheduling, the pod is evicted.
preferredDuringSchedulingRequiredDuringExecution
preferredDuringSchedulingRequiredDuringExecution
The pod is scheduled on a satisfying node if possible. If no node satisfies the rule, the pod is scheduled on another node. If node labels change after scheduling, the pod is evicted.