在Kubernetes中,podAffinity和podAntiAffinity权重是相互比较的?还是独立比较的?podAffinity和nodeAffinity呢?

1yjd4xko  于 2023-11-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(123)

在Kubernetes中,podAffinitypodAntiAffinity的权重是相互比较的吗?还是独立的?podAffinitynodeAffinity呢?在下面的例子中,podAntiAffinity会比podAffinity更重要吗?如果nodeAffinity也被添加到混合中呢?

affinity:
  podAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 50
      podAffinityTerm:
        labelSelector:
          matchExpressions:
          - key: app.kubernetes.io/name
            operator: In
            values:
            - test-1
        topologyKey: kubernetes.io/hostname

  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 100
      podAffinityTerm:
        labelSelector:
          matchExpressions:
          - key: app.kubernetes.io/name
            operator: In
            values:
            - test-2          
        topologyKey: kubernetes.io/hostname

字符串

jhiyze9q

jhiyze9q1#

如果您不覆盖默认的单个权重1,则pod和节点的所有亲和度设置的权重都是相同的。
在执行期间,节点上的亲和性条件的出现乘以条件的权重。

pod a has an affinity to b
pod a has an anti-affinity to c

new pod of type "a" to be scheduled
---
node1 runs 3 "b" pods and 1 "c" pod --> affinity score: 2 (3 "b" pods - 1 "c" pod)
node2 runs 1 "b" pod --> affinity score 1: 1 (1 "b" pod)

字符串
根据亲和度计算,尽管节点1已经在运行pod“c”,但pod将被调度到节点1上,因为3个“b”pod超过1个“c”pod。
在您的示例中,如果节点上test-1test-2的比例为1:1,则反亲和性将超过亲和性设置。如果节点上test-1test-2的比例为2:1,则(反)亲和性将相互抵消。

相关问题