apiVersion: apps/v1
kind: Deployment
metadata:
  name: affinity
  labels:
    app: affinity
spec:
  replicas: 3
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: affinity
      role: test
  template:
    metadata:
      labels:
        app: affinity
        role: test
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
          name: nginxweb
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution: # 硬策略
            nodeSelectorTerms: # 满足任意一个
            - matchExpressions: # 必须同时满足
              - key: kubernetes.io/hostname
                # In: Label 的值在某个列表中
                # NotIn: label的值不再某个列表中
                # Gt: label的值大于某个值
                # Lt: label的值小于某个值
                # Exists: 某个label存在
                # DoesNotExist: 某个label不存在
                operator: In
                values:
                - k8s-node1
          preferredDuringSchedulingIgnoredDuringExecution: # 软策略
          - weight: 1
            preference:
              matchExpressions:
              - key: com
                operator: In
                values:
                - chyidl
