带有节点选择器的 Kubernetes Pod AntiAffinity 行为

问题描述

我有一个 K8s 部署,其规范中包含节点选择器和硬 Pod 反亲和性。节点选择器将 Pod 部署限制在一个节点池中,而反亲和性限制没有两个标签为“App: test-pool”的 Pod 被安排在一起。

观察

目标节点池有 9 个节点,它们具有唯一的标签值,节点选择器使用它来定位 pod 部署。当我有 9 个部署副本时,所有副本都安排在不同的节点上,我认为这是由于反关联性。但是,一旦我将副本数增加到 10,我就会看到第 10 个 pod 也成功部署在节点池中的 9 个节点之一上,从而忽略了硬反亲和性规则。以下是部署的片段:

kind: Deployment
Metadata:
  name: test-app
  labels:
    App: test-app
spec:
  replicas: 10
  selector:
    matchLabels:
      App: test-app
  strategy:
    rollingUpdate:
      maxSurge: 34%
      maxUnavailable: 34%
    type: RollingUpdate
  template:
    Metadata:
      labels:
        App: test-app
    spec:
      nodeselector:
        app: test-pool
      tolerations:
        - key: "dedicated"
          operator: "Equal"
          value: "test-pool"
          effect: "NoSchedule"
        - key: "dedicated"
          operator: "Equal"
          value: "test-pool"
          effect: "NoExecute"
            affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - test-app
            topologyKey: kubernetes.io/hostname
   
...
...

期望

我期待参考反关联规则的调度失败。有人可以解释为什么在调度过程中会忽略 pod 反关联规则。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)