1、查看標簽 kubectl get nodes --show-labels 2、打標簽 kubectl label nodes node1.com kong=true kubectl label nodes node2.com kong=true kubectl label nodes node3.com kong=true 3、node添加親和性 spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kong operator: In values: - "true"
4、刪除label
kubectl label nodes node1.com kong-
反親和性 affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 podAffinityTerm: labelSelector: matchExpressions: - key: k8s-app operator: In values: - my-app topologyKey: kubernetes.io/hostname
節點綁定
spec:
containers:
dnsPolicy: ClusterFirst
nodeSelector:
kubernetes.io/hostname: node03.paas
污點和容忍
NoSchedule:表示 pod 不會被調度到標記為 taints 的節點,只會影響新的 pod 調度 PreferNoSchedule:NoSchedule 的軟策略版本,表示盡量不調度到污點節點上去,只會影響新的 pod 調度 NoExecute:該選項意味着一旦 Taint 生效,如該節點內正在運行的 pod 沒有對應 Tolerate 設置,會直接被逐出 # 節點添加污點 $ kubectl taint nodes node02 app=heihei:NoSchedule # 取消節點污點 kubectl taint nodes node02 app-
# 查看節點污點
kubectl describe nodes node02|grep Taints
如果 operator 的值是 Exists,則 value 屬性可省略 如果 operator 的值是 Equal,則表示其 key 與 value 之間的關系是 equal(等於) 如果不指定 operator 屬性,則默認值為 Equal 如果pod想部署到此節點,需要添加如下內容 spec: containers: - name: nginx image: nginx:1.7.9 tolerations: - key: "app" operator: "Exists" effect: "NoSchedule" #這里的值要和上面的的添加污點的值匹配上,不然調度不到
重要:如果只調度到此污點節點,pod還需要添加如下親和性
kubectl label node yq-map app=my-map
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100 podAffinityTerm: labelSelector: matchExpressions: - key: app operator: In values: - my-app
參考:https://blog.csdn.net/qq_34556414/article/details/109448632