🌎

Cluster Autoscalerを使うなら、ノードグループはAZごとに作る

2022/12/09に公開

遭遇した問題

Topology Spread Constraintsを設定したPodに対してCluster Autoscalerがノードのスケールを「させない」判断を下すことがあった。その結果PodがPendingのまま配置されないことがあった。

アプリケーション開発チームがリリースを行なった際、DeploymentのRollingUpdateによりPodが増加したが、そのPodが配置されないままになったことで発見された。

(当該Deploymentには対応するHorizontal Pod Autoscalerも存在していたので、そちら経由のPod増加で発生する可能性もあったが、その前に原因を取り除けたため発生を回避した)

https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/

原因

ノードグループが複数のアベイラビリティゾーンにまたがるように設定されていた(複数のゾーンのサブネットが割り当てられていた)。

Cluster Autoscalerを利用する場合、ノードグループはAZごとに作ることが推奨されていた。

ノードグループはAZ単位で作成することを推奨する公式Doc

https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#i-have-a-couple-of-pending-pods-but-there-was-no-scale-up

To allow CA to take advantage of topological scheduling, use separate node groups per zone. This way CA knows exactly which node group will create nodes in the required zone rather than relying on the cloud provider choosing a zone for a new node in a multi-zone node group. When using separate node groups per zone, the --balance-similar-node-groups flag will keep nodes balanced across zones for workloads that dont require topological scheduling.

https://docs.aws.amazon.com/eks/latest/userguide/autoscaling.html#cluster-autoscaler

We recommend that you configure multiple node groups, scope each group to a single Availability Zone, and enable the --balance-similar-node-groups feature. If you only create one node group, scope that node group to span over more than one Availability Zone.

ページの頭の方にはcan still consist of more than one Availability Zone or instance type.と書いてあるので紛らわしい(複数AZにまたがるノードグループを作れるのは本当なので嘘は言っていない)。

どうしてノードグループが複数AZまたぐとスケールしなくなるのか

  • 前提)ノードグループが複数AZにまたがる=各ノードのtopology.kubernetes.io/zoneの値には複数のパターンがありえる
  • CAが「どのノードグループを増やせばPodが置けるようになるかな?」と考えるときに、ノードグループごとに1台だけがサンプルとして取り上げられ、ラベル等の情報が記憶される
    • ここで以下の諸条件がマッチしてしまう
      • ノードグループはap-northeast-1aap-northeast-1cにまたがっている
      • Podはap-northeast-1aへの配置を求めている
      • 「ノードグループごとに1台」取り上げられたノードはap-northeast-1cだった
  • Podが求める条件に合うノードが無いと誤解し、スケールしないという判断になる

詳細は以下のIssue作成者により解説されている。

https://github.com/kubernetes/autoscaler/issues/4848

Discussion