Skip to content

Pod Anti-Affinity

Pod anti-affinity rules specify that pods should be placed away from (not on the same node as) other pods.

Pod Anti-Affinity - Spread
Pods spread across nodes

Mental Model

Like sitting far apart in a theater to ensure even distribution. Pod anti-affinity spreads pods across different nodes to improve fault tolerance - if one node fails, not all pods go down.

YAML Example

apiVersion: v1
kind: Pod
spec:
  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchLabels:
            app: web
        topologyKey: "kubernetes.io/hostname"
  containers:
  - name: app
    image: myapp

Common Misconceptions

  • ✗Anti-affinity prevents any pods on same node - FALSE: Only matching pods
  • ✗Anti-affinity guarantees even distribution - TRUE: But can lead to pending pods
  • ✗Anti-affinity and affinity conflict - FALSE: Can use both together

Key Takeaways

  • • Pod anti-affinity rules specify that pods should be placed away from (not on the same node as) other pods.
  • • Like sitting far apart in a theater to ensure even distribution. Pod anti-affinity spreads pods acro...
  • • Check the YAML example for implementation details
  • • Be aware of the common misconceptions listed above
Kubernetes Cosmos•An interactive learning experience
Built by GLM 4.7