A 6-replica Deployment has 3 Pods Running and 3 Pending: `0/3 nodes are available: 3 node(s) didn't match pod anti-affinity rules`.
IntermediateTroubleshootingScheduling and Pending Pods
Answer
Likely causes → Required pod anti-affinity on kubernetes.io/hostname means one replica per node. Six replicas on three nodes cannot fit. The Cluster Autoscaler can help, but only if it can add nodes.
Diagnose →
kubectl get deploy web -o jsonpath='{.spec.template.spec.affinity.podAntiAffinity}' | jq
kubectl get pods -l app=web -o wide
Fix → Switch to preferredDuringSchedulingIgnoredDuringExecution, or better, topology spread constraints:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector: {matchLabels: {app: web}}
Prevent → Reserve required anti-affinity for things that truly cannot share a node (quorum members); use spread constraints for everything else.
More on Scheduling and Pending Pods
Pods are Pending with `0/5 nodes are available: 5 Insufficient cpu. preemption: 0/5 nodes are available: 5 No preemption victims found for incoming pod.`Beginner`kubectl top nodes` shows nodes at 20% CPU, yet new Pods fail with `Insufficient cpu`. Explain it to a developer.Beginner`0/4 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }, 3 node(s) had untolerated taint {dedicated: gpu}`.BeginnerA StatefulSet Pod is Pending with `pod has unbound immediate PersistentVolumeClaims`.Beginner`0/3 nodes are available: 3 node(s) didn't match Pod's node affinity/selector.`BeginnerPods are Pending with `node(s) didn't match pod topology spread constraints` even though one zone has lots of free capacity.Intermediate