KubernetesのTopology Spread Constraintsは、Podをノード、リージョン、および可用性ゾーンにわたって均等にスケジューリングすることを可能にします。
以下のTopologySpreadConstraintsは、任意の時点で2つのノード間のPod数の差が2を超えないことを保証します。
例: 3つのノードで5つのPodを実行する場合。Kubernetesスケジューラーは、topologyKey: kubernetes.io/hostnameに基づいて、1:1:3または2:2:1のいずれかでスケジューリングします。
option 1: Maximum difference is 3-1=2
option 2: Maximum difference is 2-1=1
Enter fullscreen mode Exit fullscreen mode
最大差が3-0=3に達するため、3:2:0としてスケジューリングされることはありません。
条件が満たされない場合、Podはスケジューリングされません。whenUnsatisfiable: DoNotSchedule
同様に、複数の制約を持つことができます。スケジューラーは最適な組み合わせを特定するために、それらに対してAND演算を実行します。
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
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.