Zone に偏ってしまうことがある • レプリカ数を増やせばすべての Pod が偏って配置される可能性は低くなる (とはいえ想定しているよりも多くの Pod が停⽌する可能性はある) • Pod を分散配置して、障害や運⽤作業による影響をできるだけ⼩さくしたい! !"#$%& !"#$%' !"#$%( !""#$ !""#$ )**%+%,-$*./0)12%'3 AB )**%C%,-$*./0)12%'3 !""#% !""#% !"#$%(%DEFGHIJKLM )**%C%NOPN Q"#%DEFGH
の設定ミスがあると分散配置されないため、 マニフェスト更新のプルリクエスト作成時に バリデーションを実⾏する • Rego ⾔語でルールを記述し、OPA/Conftest を 使⽤して Label の設定チェックを実⾏ package main deny[msg] { target_kind := ["Deployment", "StatefulSet", "Rollout"] input[i].contents.kind == target_kind[_] target := input[i].contents is_replicated(target) not match_topology_spread_constraints_selector(target) msg := sprintfPod is("Pods owned by %v ¥"%v¥" must be distributed to dif ferent nodes or availability zones with topologySpreadConstraints. Configure topologySpreadConstraints field to ensure that at least node-level failures do not impact availability. If a single Pod is enough, simply set replicas t o 1 so that this rule will be passed.", [target.kind, target.metadata.name]) } # Multiple is_replicated functions are processed as OR conditions. # ref. https://www.openpolicyagent.org/docs/latest/policy-language/#incremen tal-definitions is_replicated(target) { target.spec.replicas > 1 } # If replicas field is not present, it is assumed that the number of Pods # is replicated and controlled by HPA. is_replicated(target) { not target.spec.replicas } match_topology_spread_constraints_selector(target) { labels := target.spec.template.metadata.labels constraint := target.spec.template.spec.topologySpreadConstraints[i] object.subset(labels, constraint.labelSelector.matchLabels) } +,-./012 3435678 !
Pod に関しては適⽤されず、多少 Pod が偏る可能性もある • 参考: https://github.com/kubernetes-sigs/descheduler • 複数台同時に Rolling Update を実施すると、新旧 Pod が混在して skew の計算結果が 適切なものにならず、更新完了後に Pod の数に偏りが発⽣する可能性がある • Pod の分散配置はコンテナアプリケーションを安定運⽤するための⼀つの要素に過ぎない ! "#$%&'()*+,- ./01234567*89:;<'6=>*?@<ABCDEFGH< IJGKLMNOPQR9STUVWQXYZ[\X