Evenly schedule pods using Topology Spread Constraints in AWS EKS

작성자

카테고리:

← 피드로
DEV Community · Hari Karthigasu · 2026-07-24 개발(SW)

AWS Community Builders  profile image Hari Karthigasu

The Kubernetes Topology Spread Constraints allow scheduling pods evenly across nodes, regions and availability zones.

The following TopologySpreadConstraints ensure that at any given time, the difference in the number of pods between two nodes never exceeds 2.

Instance: If you run 5 pods on 3 nodes. Kubernetes scheduler will schedule them as either 1:1:3 or 2:2:1 based on topologyKey: kubernetes.io/hostname

option 1: Maximum difference is 3-1=2
option 2: Maximum difference is 2-1=1

Enter fullscreen mode Exit fullscreen mode

It’ll never be scheduled as 3:2:0 as the maximum difference reaches 3-0=3.

The pods will not be scheduled if the condition is not met. whenUnsatisfiable: DoNotSchedule

Likewise, we can have multiple constraints. Scheduler performs AND operations among them to identify the best combination.

      topologySpreadConstraints:
      - maxSkew: 2
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app.kubernetes.io/application: backend
            app.kubernetes.io/name: backend
_      # Setting maxSkew to 1 ensures that pods are (almost) evenly distributed across the AZs.  _      
      - maxSkew: 1
        topologyKey: topology.kubernetes.io/zone
_        # Setting ScheduleAnyway ensures that during an AZ failure or resource starvation, pods will be scheduled to one of the active AZs by bypassing maxSkew._
        whenUnsatisfiable: ScheduleAnyway
        labelSelector:
          matchLabels:
            app.kubernetes.io/application: backend
            app.kubernetes.io/name: backend

Enter fullscreen mode Exit fullscreen mode

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다