简体   繁体   English

如何在 Kubernetes StatefulSet 中保证跨 AZ 均匀分布 Pod

[英]How to guarantee even spread pod distribution across AZ in Kubernetes StatefulSet

I deployed a K8s StatefulSet with 30 replicas (or N replicas, where N is multiple of 3) in EKS Cluster.我在 EKS 集群中部署了一个具有 30 个副本(或 N 个副本,其中 N 是 3 的倍数)的 K8s StatefulSet

EKS cluster is with 3 nodes, one node for one AZ, and I want to guarantee with Kubernetes Affinity/AntiAffinity the equal distribution of pods across different AZ. EKS 集群有 3 个节点,一个节点用于一个 AZ,我想通过 Kubernetes Affinity/AntiAffinity保证Pod 在不同 AZ 之间的平均分布。

us-west-2a (n nodes) -> N/3 pods
us-west-2b (m nodes) -> N/3 pods
us-west-2c (o nodes) -> N/3 pods

Thanks谢谢

While this is too possible with node affinity, a straight forward way is the use of topologySpreadContraints, here's the k8s documentation, diagrams and examples to see it in action.虽然这对于节点亲和力来说太可能了,但直接的方法是使用 topologySpreadContraints,这里是 k8s 文档、图表和示例以查看它的实际应用。

You can always use selectors and default labels which you get from AWS.您始终可以使用从 AWS 获得的选择器和默认标签。 A simple pod spec example is here一个简单的 pod 规范示例在这里

topologySpreadConstraints:
  - maxSkew: 1
    topologyKey: "topology.kubernetes.io/zone"
    whenUnsatisfiable: DoNotSchedule
    labelSelector:
      matchLabels:
        app: myapp

You can include skew and other options based on the need as described here: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/您可以根据此处所述的需要包括偏斜和其他选项: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Kubernetes集群中使用现有的Statefulset运行Pod? - How to run pod with existing statefulset in kubernetes cluster? 如何在 statefulset 中为 kubernetes pod 设置主机名 - How to set hostname for kubernetes pod in statefulset 如何确保我的Kubernetes EBS卷与部署位于相同的可用区中? - How to guarantee that my Kubernetes EBS volume will be in the same AZ as the deployment? Kubernetes:如何删除由 StatefulSet 管理的特定 Pod 而不会重新创建它? - Kubernetes : How to delete a specific pod managed by StatefulSet without it being recreated? 如何使用命名空间在 Kubernetes 中的 Statefulset POD 中打开 shell - How to open a shell within Statefulset POD in Kubernetes using namespace 当 kubernetes 中存在 pod 安全策略时,如何部署 statefulset - how to deploy a statefulset when a pod security policy is in place in kubernetes Kubernetes-如何创建每个节点一个Pod的StatefulSet? - Kubernetes - How to create a StatefulSet with one Pod per Node? Kubernetes StatefulSet - 在 pod 重启时不恢复数据 - Kubernetes StatefulSet - does not resatore data on pod restart Kubernetes:仅公开 StatefulSet 的单个 pod - Kubernetes: Expose only single pod of StatefulSet 将 Kubernetes statefulset pod 移动到另一个节点 - Move Kubernetes statefulset pod to another node
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM