k8s pod节点亲和性nodeAffintiy

1. pod节点亲和性nodeAffintiy

  • nodeAffinity:节点亲和性,与nodeSelector作用一样,但相比更灵活,满足更多条件,诸如:

    • 匹配有更多的逻辑组合,不只是字符串的完全相等

    • 调度分为软策略和硬策略,而不是硬性要求

      • 硬(required):必须满足

      • 软(preferred):尝试满足,但不保证

  • 操作符:In、NotIn、Exists、DoesNotExist、Gt、Lt

  • 示例:
    image

    • 代码:

      apiVersion: v1
      kind: Pod
      metadata:
        name: with-node-affinity
      spec:
        affinity:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
              - matchExpressions:
                - key: gpu
                  operator: In
                  values:
                  - nvidia-tesla
        preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 1
          preference:
            matchExpressions:
            - key: group
              operator: In
              values:
              - ai
        containers:
        - name: web
          image: nginx
      
原文地址:https://www.cnblogs.com/scajy/p/15481764.html