51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

k8s Pod调度之反亲和性podAntiAffinity

k8s Pod调度之反亲和性podAntiAffinity

1.给节点打标签

kubectl label nodes master231 dc=yizhuang

kubectl label nodes worker232 dc=jiuxianqiao

kubectl label nodes worker233 dc=baimei

kubectl get nodes --show-labels

2.资源清单

cat 01-podAntiAffinity.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-tolerations-podantiaffinity
spec:
  replicas: 10
  selector:
    matchExpressions:
    - key: apps
      values: 
      - "v1"
      - "v2"
      operator: In
  template:
    metadata:
      labels:
        apps: v1
    spec:
      # 基于节点的标签进行调度,将Pod调度到包含key为type,value为ssd的节点上。
      # nodeSelector:
      #   type: ssd
      #
      # 配置亲和性
      affinity:
        # 配置Pod反亲和性
        podAntiAffinity:
           # 硬限制
           requiredDuringSchedulingIgnoredDuringExecution:
             # 指定拓扑域,可以理解为基于哪个标签进行分配
           - topologyKey: dc
             # 配置标签选择器
             labelSelector:
                # 基于Pod标签匹配
                matchLabels:
                  apps: v1 
      # 配置污点容忍
      tolerations:
      - key: school
        operator: Exists
      - key: class
        effect: NoSchedule
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: v1
        image: harbor.baimei.com/baimei-apps/apps:v1
赞(6)
未经允许不得转载:工具盒子 » k8s Pod调度之反亲和性podAntiAffinity