背景:某个deployment有9个pod,但是k8s调度到了两个节点上,导致prometheus监控报该节点:

NodeCPUUsageExceed

为了使9个pod 不部署到相同的节点,所以需要配置pod的反亲和性,假如pod有标签app=test。配置反亲和性的规则为 :不与app=test的pod调度到同一个节点:
硬限制(requiredDuringSchedulingIgnoredDuringExecution)

    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                      - test
              topologyKey: kubernetes.io/hostname

软限制(preferredDuringSchedulingIgnoredDuringExecution)

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

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐