Member-only story
Understanding Kubernetes: Part 25 Affinity and Anti-Affinity
3 min readFeb 4, 2025
📢 If you’ve been following our Kubernetes series 2025, welcome back! For new readers, check out Part 24: Taints and Tolerations
📖 Not a Medium member? No worries! Here’s the free link: Part 25 — Affinity and Anti-Affinity
What is Node Affinity?
Node Affinity is a rule that ensures Pods are scheduled on specific nodes based on defined labels.
What is Pod Affinity and Anti-Affinity?
- Pod Affinity ensures that Pods are scheduled close to other Pods based on label selectors.
- Pod Anti-Affinity prevents Pods from being scheduled on the same nodes or within a failure domain.
Use Cases
Affinity and Anti-Affinity are useful in various scenarios:
1. Node Affinity
- Ensuring that workloads requiring SSD storage run on nodes labeled with
storage=ssd
. - Running GPU-intensive workloads on nodes labeled
gpu=true
.
2. Pod Affinity
- Ensuring that microservices communicate efficiently by scheduling them on the same node.
- Keeping interdependent applications (e.g…