Kubernetes Affinity is a set of scheduling rules used to control which nodes a Pod is eligible to be scheduled on, or which Pods are allowed to be co-located. There are three main types:
- Node Affinity (
NodeAffinity): Controls the relationship between Pods and Nodes (e.g., ensuring a Pod runs on a node with specific hardware). - Pod Affinity (
PodAffinity): Controls the relationship between Pods, allowing a Pod to be scheduled in the same location as another Pod. - Pod Anti-Affinity (
PodAntiAffinity): Controls the relationship between Pods, preventing a Pod from being scheduled in the same location as another Pod.
Each type supports both hard (required) and soft (preferred) scheduling policies to determine if the rule must be strictly followed or just attempted.