Advanced Scheduling in Kubernetes

Node & Pod Affinity/Anti-Affinity, Taints and Tolerations

Amulya Reddy Konda
2 min readMar 22, 2021

Scheduler is a Kubernetes controller listening if a new pod is created and figure out right node by filtering and scoring

Node Affinity/Anti-Affinity

Affinity: If we need a pod to be in a node, based on key-label and value-label
Anti-Affinity: We don't want two replicas of pods in the same node

Node Affinity

Pod Anti-Affinity

TopologyKey — it looks for the hostname, if it matches it doesn’t schedule (since we mentioned podAntiAffinity) that pod to that node.

Taints and Tolerations

Taints — (on Nodes) Restriction of Pods to schedule on a Node
Toleration - (on Pods) Added to Pod that can Tolerate the Taint

Taints Example

kubectl taint nodes <node-name> key=value:taint-effect3 Taint Effects
1. NoSchedule - Taint & Toleration is checked during Scheduling
2. PreferNoSchedule - Not guaranteed
3. NoExecute - Existing pods that don't tolerate taint are ejected
pod definition

Update the evicted pods as in above image

Taint NoSchedule is set on Master node so that pods are not deployed on master node

--

--