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:
operator
: in
values:
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 設定,會直接被逐出
# 節點新增汙點
# 取消節點汙點
operator
的值是 exists,則 value 屬性可省略
如果 operator
的值是 equal,則表示其 key 與 value 之間的關係是 equal(等於)
如果不指定
operator
屬性,則預設值為 equal
如果pod想部署到此節點,需要新增如下內容
spec:
containers:
-name: nginx
image: nginx:
1.7.9
tolerations:
- key: "
"operator: "
exists
"effect:
"noschedule
" #這裡的值要和上面的的新增汙點的值匹配上,不然排程不到
重要:如果只排程到此汙點節點,pod還需要新增如下親和性
affinity:podantiaffinity:
preferredduringschedulingignoredduringexecution:
- weight: 100podaffinityterm:
labelselector:
matchexpressions:
operator: in
values:
參考:
親和性 反親和性 汙點 容忍
在預設的k8s排程中,一般經過預選和優選即可完成排程,但是生產的實際使用中,考慮到部分業務的特殊性,一般會手動進行一些 指定 k8s 把這些 指定 分為nodeaffinity 節點親和性 podaffinity pod 親和性 以及 podantiaffinity pod 反親和性 這在排程過程中...
K8S汙點機制
汙點kubectl taint 汙點 taint 的組成 使用 kubectl taint 命令可以給某個 node 節點設定汙點,node 被設定上汙點之後就和 pod 之間存在了一種相 斥的關係,可以讓 node 拒絕 pod 的排程執行,甚至將 node 已經存在的 pod 驅逐出去 每個汙點...
k8s 給節點打標籤和打汙點
打標籤 kubectl label node node1 env role prod 檢視標籤 kubectl get nodes show labels kubectl taint node node名 key value 汙點三個可選值 noschedule 一定不被排程 prefernosch...