在不同的物理服务器上安排 kubernetes pods

schedule kubernetes pods on different physical server

在我的集群中有 30 个虚拟机,它们位于 3 个不同的物理服务器中。我想在不同的物理服务器上部署每个工作负载的不同副本。 我知道我可以使用 podAntiAffinity 在不同的 VM 上部署副本,但我找不到任何方法来保证在不同的物理服务器上传播复制。

我想知道有什么方法可以解决这个挑战吗?

我相信你已经给出了答案;)

我去看了 Kubernetes 模式一书(PDF 在 here 中免费提供),看看那里是否有与之相关的内容,并准确地找到了:

To express how Pods should be spread to achieve high availability, or be packed and co-located together to improve latency, Pod affinity and antiaffinity can be used.

Node affinity works at node granularity, but Pod affinity is not limited to nodes and can express rules at multiple topology levels. Using the topologyKey field, and the matching labels, it is possible to enforce more fine-grained rules, which combine rules on domains like node, rack, cloud provider zone, and region [...]

我也非常喜欢 k8s 文档,它们非常完整并且充满了示例,所以也许您可以从 here 中获得一些想法。我认为主要想法是创建您自己的 affinity/antiaffinity 规则。

------------------------------------ 编辑 ----------------------------------

k8s 1.18 版本中有一项新功能可能是更好的解决方案。

它被称为:Pod Topology Spread Constraints:

You can use topology spread constraints to control how Pods are spread across your cluster among failure-domains such as regions, zones, nodes, and other user-defined topology domains. This can help to achieve high availability as well as efficient resource utilization.