親和性 反親和性 汙點 容忍

2021-10-14 02:41:34 字數 4500 閱讀 4162

在預設的k8s排程中,一般經過預選和優選即可完成排程,但是生產的實際使用中,考慮到部分業務的特殊性,一般會手動進行一些"指定", k8s 把這些"指定"分為nodeaffinity(節點親和性)、podaffinity(pod 親和性) 以及 podantiaffinity(pod 反親和性), 這在排程過程中,稱之為親和性排程,親和性排程可以分成軟策略(preferredduringschedulingignoredduringexecution )和硬策略(requiredduringschedulingignoredduringexecution)兩種方式,軟策略意思是如果現在沒有滿足排程要求要求的話,那就跳過這條策略,繼續排程,總結起來就是"有則用之,無則跳過", 而硬策略相對就強硬很多,如果不滿足排程策略,則不停重試,直到滿足策略。

:# 硬策略

nodeselectorterms:-

matchexpressions:-

key: kubernetes.io/hostname

operator

: notin

values

:- nginx-node001

preferredduringschedulingignoredduringexecution

:# 軟策略

-weight:1

preference

:matchexpressions:-

key: webnode

operator

: in

values:-

true

pod 有podaffinity和podantiaffinity,但是node 卻只有nodeaffinity,這是因為operator , operator 是匹配表示式的操作符,nodeaffinity支援in, notin, exists, doesnotexist, gt和lt,所以想支援"nodeantiaffinity"只要operator使用notin或者doesnotexist就可以實現了。

:# 硬策略

labelselector:-

matchexpressions:-

key: name

operator

: in

values

:- podaffinity-nginx

topologykey

: failure-domain.beta.kubernetes.io/zone

podantiaffinity

:preferredduringschedulingignoredduringexecution:-

weight

: 100 // 1-

100podaffinityterm

:labelselector

:matchexpressions:-

key: security

operator

: in

values

:- securitya

topologykey

: kubernetes.io/securitya

podaffinity的operator支援in, notin, exists, dosenotexit. 相對nodeaffinity,podaffinity多了乙個topologykey,topologykey可以理解為拓撲域,在yaml裡的意思是排程需要對應的node有對應的標籤,而不關心這個label對應的值,假設反topologykey是idc的維度,公司有北京上海2個idc,pod的副本數量為2,那麼pod在完成了topologykey-idc=beijing之後,根據podantiaffinity的策略,則不會在同樣個zone的topologykey在建立了,而會建立在shanghai,從而做到了idc的均衡部署。

親和性和反親和性的作用是為了讓pod可以根據需要排程到自己像分配的乙個或者一組node上,汙點的作用其實就是反過來,就是給node打上乙個特殊的標籤,讓該node不再被分配pod,除非該pod容忍了該汙點。假設有伺服器硬體發生了預告警,或者伺服器維保到期需要預下線,那麼從伺服器等待維護/預下線到真正伺服器不在提供服務的週期裡,該node不會被排程。

taints
kubectl taint nodes node-name key=value:effect

# key 和 value 為汙點標籤, value 可以為空,effect 描述汙點的作用

effect 支援以下3種:
#給nodea打汙點標籤

kubectl taint nodes nodea tainta=node:noschedule

#檢視kubectl describe node nodea |

grep taints

#取消汙點

假設nodea存在"node-role.kubernetes.io/maintenance"的標籤,該pod可以容忍noschedule的汙點。容忍存在以下預設場景:

pod 的親和性,反親和性 實驗

pod 的親和性,反親和性 實驗 目錄 設定node01和node02節點,擁有標籤 test a root master demo kubectl label nodes node test a overwrite node node01 labeled node node02 labeled 檢...

親和性分析

小編最近在看 robert layton 的資料探勘,寫隨筆一方面為了加深印象,一方面為了以後方便看。通常 為了增大需求,常常把顧客願意一起買的東西放在一起。這樣顧客買的機率較大,能夠刺激消費。最簡單的例子就是,你買了羊肉卷,那你肯定也想買墨魚丸,買了墨魚丸,想到了火鍋底料,如果你沒有想到的化,那麼...

k8s 節點親和性和汙點容忍

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.c...