其他分享
首页 > 其他分享> > k8s亲和性应用示例

k8s亲和性应用示例

作者:互联网

由于特殊需求,需要将特定命名空间下的pod调度到特定的节点上,本来直接使用硬节点亲和性就可以了,但是后面由于安装了中间件nacos,这个本身自带pod亲和性,就需要同时配置pod亲和性和node亲和性,这里将改好的配置做个记录,如下:

    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: xiamentag
                operator: In
                values:
                - xiamen
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - nacos
              topologyKey: kubernetes.io/hostname
            weight: 100

需要注意的是将原来nacos的pod硬亲和性改成软亲和性才可以,不然会报错

标签:matchExpressions,示例,亲和性,nacos,key,operator,pod,k8s
来源: https://blog.51cto.com/riverxyz/2678969