k8s中反亲和力配置 - kilig-linux mint

kilig-linux mintkilig-linux mint

分享运维中出现的问题,并分享运维中的心得!

k8s中反亲和力配置

当一个pod在同一台服务器上,同时这个pod如果消耗了大量资源,就需要进行反亲和力配置,让这个pod不在同一节点上。
参考如下

spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - store
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: redis-server
        image: redis:3.2-alpine
#最新配置
  spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:    
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - ${DOCKER_NAME}
              topologyKey: "kubernetes.io/hostname"

参考链接https://kubernetes.io/zh/docs/concepts/scheduling-eviction/assign-pod-node/

本原创文章未经允许不得转载 | 当前页面:kilig-linux mint » k8s中反亲和力配置

评论