我们如何在 pod 亲和/反亲和中将 StatefulSet 的一个 pod 分配给 Kubernetes 集群的特定节点

How can we assign one of the pod's of StatefulSet to a specific node of a Kubernetes cluster in pod affinity / antiaffinity

我有一个 7 节点集群。我有一个应用程序 'A' 在随机 3 个节点中有 3 个副本 运行ning。我有另一个应用程序 'B' 有 5 个副本,现在我只需要将 'B' 的副本之一分配给与 'A' 相同的节点。其他4个副本可以运行在不同的节点。

Node 1  -   A1
Node 2  -   B2
Node 3  -   B3
Node 4  -   A2, B1
Node 5  -   B4
Node 6  -   A3
Node 7  -   B5
  • 相似性规则 1:同类型的 pods 会互相推动
  • 亲和法则2:不同类型的pods会互相吸引

根据这些规则,您可以实现如下目标:

Node 1: A1, B1
Node 2: A2, B2
Node 3: A3, B3
Node 4: B4
Node 5: B5
... ...

但是,如果您将污点添加到 Node:1,2 这样就无法在这些节点上安排 B pods。并向 Node:4、5、6、7 添加污点,这样就无法在这些节点上安排 A。

那么你最终会得到以下分布:

Node 1  -   A1
Node 2  -   A2
Node 3  -   A3, B1
Node 4  -   B2
Node 5  -   B3
Node 6  -   B4
Node 7  -   B5