Kubernetes Affinity & Anti-Affinity Rules
In Kubernetes, Affinity and Anti-Affinity are scheduling rules that control how pods are placed across nodes or in relation to other pods, enabling more intelligent workload distribution based on data locality, fault tolerance, or workload segregation. Think of them as "rules of attraction and repulsion"—Affinity expresses a desire for a pod to be near something (“I want to be close to something”), while Anti-Affinity expresses a desire to avoid proximity (“I want to avoid being near something”). These rules come in two main types: Node Affinity, which defines constraints on which nodes a pod can be scheduled to, and Pod Affinity/Anti-Affinity, which sets constraints based on the presence or absence of other pods.
Keep reading with a 7-day free trial
Subscribe to Pods & Pixels to keep reading this post and get 7 days of free access to the full post archives.