简体   繁体   English

Kubernetes pod 亲和性 - 在不同节点上调度 pod

[英]Kubernetes pod affinity - Scheduling pods on different nodes

We are running our application with 3 pods on a 3 node kubernetes cluster.我们在 3 节点 kubernetes 集群上运行带有 3 个 pod 的应用程序。 When we deploy out application, sometimes, pods are getting scheduled to the same kubernetes node.当我们部署应用程序时,有时,Pod 会被调度到同一个 kubernetes 节点。

We want our pods to scheduled in such a way that it spread our pods across nodes ( no 2 pods of the same application should be same node).我们希望我们的 pod 以这样一种方式调度,它可以将我们的 pod 分布在节点之间(同一应用程序的 2 个 pod 不应是同一个节点)。 Infact, as per documentation( https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ ), kubernetes already does a good job in this.事实上,根据文档( https://kubernetes.io/docs/concepts/configuration/assign-pod-node/),kubernetes在这方面已经做得很好。 However, if it doesn't find resources, it schedules it to the same node.但是,如果它没有找到资源,它会将其调度到同一个节点。 How do it make it a hard constraint ?它如何使它成为一个硬约束?

Requirement: We want the deployment to fail or be in pending state if the pods don't obey the constraints (no 2 pods of the same application should be same node)要求:如果 pod 不遵守约束,我们希望部署失败或处于挂起状态(同一应用程序的 2 个 pod 不应是同一节点)

i think this one will work我认为这个会奏效

affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - <VALUE>
        topologyKey: "kubernetes.io/hostname"

For more reference you can visit : https://thenewstack.io/implement-node-and-pod-affinity-anti-affinity-in-kubernetes-a-practical-example/如需更多参考,您可以访问: https : //thenewstack.io/implement-node-and-pod-affinity-anti-affinity-in-kubernetes-a-practical-example/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM