小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Kubernetes K8S之固定節(jié)點(diǎn)nodeName和nodeSelector調(diào)度詳解

 小仙女本仙人 2022-05-22 發(fā)布于北京

 

Kubernetes K8S之固定節(jié)點(diǎn)nodeName和nodeSelector調(diào)度詳解與示例

 

主機(jī)配置規(guī)劃

服務(wù)器名稱(hostname)系統(tǒng)版本配置內(nèi)網(wǎng)IP外網(wǎng)IP(模擬)
k8s-master CentOS7.7 2C/4G/20G 172.16.1.110 10.0.0.110
k8s-node01 CentOS7.7 2C/4G/20G 172.16.1.111 10.0.0.111
k8s-node02 CentOS7.7 2C/4G/20G 172.16.1.112 10.0.0.112

 

nodeName調(diào)度

nodeName是節(jié)點(diǎn)選擇約束的最簡(jiǎn)單形式,但是由于其限制,通常很少使用它。nodeName是PodSpec的領(lǐng)域。

pod.spec.nodeName將Pod直接調(diào)度到指定的Node節(jié)點(diǎn)上,會(huì)【跳過(guò)Scheduler的調(diào)度策略】,該匹配規(guī)則是【強(qiáng)制】匹配。可以越過(guò)Taints污點(diǎn)進(jìn)行調(diào)度。

nodeName用于選擇節(jié)點(diǎn)的一些限制是:

  • 如果指定的節(jié)點(diǎn)不存在,則容器將不會(huì)運(yùn)行,并且在某些情況下可能會(huì)自動(dòng)刪除。
  • 如果指定的節(jié)點(diǎn)沒(méi)有足夠的資源來(lái)容納該P(yáng)od,則該P(yáng)od將會(huì)失敗,并且其原因?qū)⒈恢赋?,例如OutOfmemory或OutOfcpu。
  • 云環(huán)境中的節(jié)點(diǎn)名稱并非總是可預(yù)測(cè)或穩(wěn)定的。

 

nodeName示例

獲取當(dāng)前的節(jié)點(diǎn)信息

1 [root@k8s-master scheduler]# kubectl get nodes - o wide
  2 NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER- RUNTIME
  3 k8s-master Ready master 42d v1. 172.16   。172.16 。 110     <無(wú)> CentOS Linux (Core)     3el7.x 11062 .el7.x 1064 docker: // 19.3 - 4 k8s-node01 4.7.8 4 k8s-node01 4.8.7 <none> 22d v1. 17.4 172.16。1.111     <無(wú)> CentOS Linux 7(內(nèi)核)    3.10 . 0 - 1062
    .el7.x86_64 docker: // 19.3.8 
5 k8s-node02 就緒 <none> 42d v1. 17.4    172.161.112    <無(wú)> CentOS Linux 7 (Core)    3.10。0 - 1062 .el7.x86_64 泊塢窗:// 19.3.8

 

當(dāng)nodeName指定節(jié)點(diǎn)存在

要運(yùn)行的yaml文件

1 [root@k8s-master scheduler]# pwd 
2 /root/k8s_practice/ scheduler
 3 [root@k8s-master scheduler]# cat scheduler_nodeName.yaml 
 4 apiVersion: apps/ v1
 5  kind: Deployment
 6  metadata:
 7    name: scheduler-節(jié)點(diǎn)名-部署
8個(gè)   標(biāo)簽:
 9     應(yīng)用程序:節(jié)點(diǎn)名-部署
10 規(guī)范:
 11   副本:5 
12   選擇器:
 13     匹配標(biāo)簽:
 14       應(yīng)用程序:myapp
 15   模板:
 16     metadata:
17       labels:
18         app: myapp
19     spec:
20       containers:
21       - name: myapp-pod
22         image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1
23         imagePullPolicy: IfNotPresent
24         ports:
25           - containerPort: 80
26       # 指定節(jié)點(diǎn)運(yùn)行
27       nodeName: k8s-master

 

運(yùn)行yaml文件并查看信息

1 [root@k8s-master scheduler]# kubectl apply -f scheduler_nodeName.yaml 
 2 deployment.apps/scheduler-nodename- deploy created
 3 [root@k8s- master scheduler]# 
 4 [root@k8s-master scheduler]# kubectl get deploy -o wide
 5 NAME READY UP-TO- DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
 6 scheduler-nodename-deploy    0 / 5      5             0            6s myapp-pod registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1 app= myapp
 7 [root@k8s-master scheduler]# 
 8 [root@k8s-master scheduler]# kubectl get rs -o wide
 9  NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
 10 scheduler-nodename-deploy-d5c9574bd    5          5          5        15s myapp-pod registry.cn-beijing. aliyuncs.com/google_registry/myapp:v1 app=myapp,pod-template-hash= d5c9574bd
 11 [root@k8s- master scheduler]# 
 12 [root@k8s-master scheduler]# kubectl get pod - o wide
 13 NAME READY STATUS RESTARTS AGE IP 節(jié)點(diǎn) NOMINATED READINESS GATES
 14 scheduler-nodename-deploy-d5c9574bd-6l9d8    1 / 1      Running    0           23s    10.244。0.123    k8s-master <none> <none>
 15 scheduler-nodename-deploy-d5c9574bd-c82cc    1 / 1      Running    0           23s    10.244。0.119    k8s-master <none> <none>
 16 scheduler-nodename-deploy-d5c9574bd-dkkjg    1 / 1     運(yùn)行   0           23s    10.244。0.122    k8s-master <none> <none>
 17 scheduler-nodename-deploy-d5c9574bd-hcn77    1 / 1     運(yùn)行   0           23s    10.244。0.121    k8s-master <none> <none>
 18 scheduler-nodename-deploy-d5c9574bd-zstjx    1 / 1     運(yùn)行   0           23s    10.244。0.120    k8s-master <無(wú)> <無(wú)>

由上可見(jiàn),yaml文件中nodeName: k8s-master生效,所有pod被調(diào)度到了k8s-master節(jié)點(diǎn)。如果這里是nodeName: k8s-node02,那么就會(huì)直接調(diào)度到k8s-node02節(jié)點(diǎn)。

 

當(dāng)nodeName指定節(jié)點(diǎn)不存在

要運(yùn)行的yaml文件

1 [root@k8s-master scheduler]# pwd 
2 /root/k8s_practice/ scheduler
 3 [root@k8s-master scheduler]# cat scheduler_nodeName_02.yaml 
 4 apiVersion: apps/ v1
 5  kind: Deployment
 6  metadata:
 7    name: scheduler-節(jié)點(diǎn)名-部署
8個(gè)   標(biāo)簽:
 9     應(yīng)用程序:節(jié)點(diǎn)名-部署
10 規(guī)范:
 11   副本:5 
12   選擇器:
 13     匹配標(biāo)簽:
 14       應(yīng)用程序:myapp
 15   模板:
16     metadata:
17       labels:
18         app: myapp
19     spec:
20       containers:
21       - name: myapp-pod
22         image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1
23         imagePullPolicy: IfNotPresent
24         ports:
25           - containerPort: 80
26       # 指定節(jié)點(diǎn)運(yùn)行,該節(jié)點(diǎn)不存在
27       nodeName: k8s-node08

 

運(yùn)行yaml文件并查看信息

1 [root@k8s-master scheduler]# kubectl apply -f scheduler_nodeName_02.yaml 
 2 deployment.apps/scheduler-nodename- deploy created
 3 [root@k8s- master scheduler]# 
 4 [root@k8s-master scheduler]# kubectl get deploy -o wide
 5 NAME READY UP-TO- DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
 6 scheduler-nodename-deploy    0 / 5      5             0            4s myapp-pod registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1 app= myapp
 7[root@k8s- master scheduler]# 
 8 [root@k8s-master scheduler]# kubectl get rs - o wide
 9  NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
 10 scheduler-nodename-deploy-75944bdc5d    5          5          0        9s myapp-pod registry .cn-beijing.aliyuncs.com/google_registry/myapp:v1 app=myapp,pod-template-hash= 75944bdc5d
 11 [root@k8s- master scheduler]# 
 12 [root@k8s-master scheduler]# kubectl get pod -o寬
13 NAME READY STATUS RESTARTS AGE IP Node NOMINATED READINESS GATES
 14 scheduler-nodename-deploy-75944bdc5d-c8f5d    0 / 1      Pending    0           13s <none> k8s-node08 <none> <none>
 15 scheduler-nodename-deploy-75944bdc5d-hfdlv    0 / 1      Pending    0           13s <none> k8s-node08 <none> <none>
 16 scheduler-nodename-deploy-75944bdc5d-q9qgt    0 / 1      Pending    0           13s <none> k8s-node08 <none> <
無(wú)>17 scheduler-nodename-deploy-75944bdc5d-q9zl7    0 / 1      Pending    0           13s <none> k8s-node08 <none> <none>
 18 scheduler-nodename-deploy-75944bdc5d-wxsnv    0 / 1      Pending    0           13s <none> k8s-node08 <無(wú)> <無(wú)>

由上可見(jiàn),如果指定的節(jié)點(diǎn)不存在,則容器將不會(huì)運(yùn)行,一直處于Pending 狀態(tài)。

 

nodeSelector調(diào)度

nodeSelector是節(jié)點(diǎn)選擇約束的最簡(jiǎn)單推薦形式。nodeSelector是PodSpec的領(lǐng)域。它指定鍵值對(duì)的映射。

Pod.spec.nodeSelector是通過(guò)Kubernetes的label-selector機(jī)制選擇節(jié)點(diǎn),由調(diào)度器調(diào)度策略匹配label,而后調(diào)度Pod到目標(biāo)節(jié)點(diǎn),該匹配規(guī)則屬于【強(qiáng)制】約束。由于是調(diào)度器調(diào)度,因此不能越過(guò)Taints污點(diǎn)進(jìn)行調(diào)度。

 

nodeSelector示例

獲取當(dāng)前的節(jié)點(diǎn)信息

1 [root@k8s-master ~]# kubectl get node -o wide --show- labels
 2 NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER- RUNTIME LABELS
 3 k8s-master Ready master 42d v1。17.4    172.16。1.110    <無(wú)> CentOS Linux 7 (Core)    3.100 - 1062 .el7.x86_64 docker: // 19.3.8 beta./arch=amd64,beta./os=linux,/arch=amd64,/hostname=k8s-大師,/os=linux,node-role./master= 
4k8s-node01 就緒 <無(wú)> 42d v1. 17.4    172.16。1.111    <無(wú)> CentOS Linux 7 (Core)    3.100 - 1062 .el7.x86_64 docker: // 19.3.8 beta./arch=amd64,beta./os=linux,/arch=amd64,/hostname=k8s- node01,/os=linux 
5 k8s-node02 Ready <none> 42d v1. 17.4    172.16。1.112    <無(wú)> CentOS Linux 7 (Core)    3.10。0 - 1062 .el7.x86_64 泊塢窗://19.3.8     beta./arch=amd64,beta./os=linux,/arch=amd64,/hostname=k8s-node02,/os=linux

 

添加label標(biāo)簽

運(yùn)行kubectl get nodes以獲取群集節(jié)點(diǎn)的名稱。然后可以對(duì)指定節(jié)點(diǎn)添加標(biāo)簽。比如:k8s-node01的磁盤(pán)為SSD,那么添加disk-type=ssd;k8s-node02的CPU核數(shù)高,那么添加cpu-type=hight;如果為Web機(jī)器,那么添加service-type=web。怎么添加標(biāo)簽可以根據(jù)實(shí)際規(guī)劃情況而定。

 1 ### 給k8s-node01 添加指定標(biāo)簽
 2 [root@k8s-master ~]# kubectl label nodes k8s-node01 disk-type=ssd
 3 node/k8s-node01 labeled
 4 #### 刪除標(biāo)簽命令 kubectl label nodes k8s-node01 disk-type-
 5 [root@k8s-master ~]# 
 6 [root@k8s-master ~]# kubectl get node --show-labels
 7 NAME         STATUS   ROLES    AGE   VERSION   LABELS
 8 k8s-master   Ready    master   42d   v1.17.4   beta./arch=amd64,beta./os=linux,/arch=amd64,/hostname=k8s-master,/os=linux,node-role./master=
 9 k8s-node01 Ready <none> 42d v1. 17.4    beta./arch=amd64,beta./os=linux,disk-type=ssd,/arch=amd64,/主機(jī)名=k8s-node01,/os = linux
 10 k8s-node02 就緒 <無(wú)> 42d v1。17.4    beta./arch=amd64,beta./os=linux,/arch=amd64,/主機(jī)名=k8s-node02,/os=linux

由上可見(jiàn),已經(jīng)為k8s-node01節(jié)點(diǎn)添加了disk-type=ssd 標(biāo)簽。

 

當(dāng)nodeSelector標(biāo)簽存在

要運(yùn)行的yaml文件

1 [root@k8s-master scheduler]# pwd 
2 /root/k8s_practice/ scheduler
 3 [root@k8s- master scheduler]# 
 4 [root@k8s-master scheduler]# cat scheduler_nodeSelector.yaml 
 5 apiVersion:apps/ v1
 6種 :部署
7 元數(shù)據(jù):
 8   名稱:scheduler-nodeselector-部署
9   標(biāo)簽:
 10     應(yīng)用程序:nodeselector-部署
11 規(guī)范:
 12   副本:5 
13   選擇器:
 14      matchLabels:
 15       app: myapp
16   template:
17     metadata:
18       labels:
19         app: myapp
20     spec:
21       containers:
22       - name: myapp-pod
23         image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1
24         imagePullPolicy: IfNotPresent
25         ports:
26           - containerPort: 80
27       # 指定節(jié)點(diǎn)標(biāo)簽選擇,且標(biāo)簽存在
28       nodeSelector:
29         disk-type: ssd

 

運(yùn)行yaml文件并查看信息

1 [root@k8s-master scheduler]# kubectl apply -f scheduler_nodeSelector.yaml 
  2 deployment.apps/scheduler-nodeselector- deploy created
  3 [root@k8s- master scheduler]# 
  4 [root@k8s-master scheduler]# kubectl get deploy -o wide
  5 NAME READY Up- TO- DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
  6 scheduler-nodeselector-deploy     5 / 5      5             5             10s myapp-pod registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1 app= myapp
  7 [root@k8s-主調(diào)度器]# 
  8 [root@k8s-master scheduler]# kubectl get rs - o wide
 9  NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
 10 scheduler-nodeselector-deploy-79455db454    5          5          5        14s myapp-pod registry .cn-beijing.aliyuncs.com/google_registry/myapp:v1 app=myapp,pod-template-hash= 79455db454
 11 [root@k8s- master scheduler]# 
 12 [root@k8s-master scheduler]# kubectl get pod -o寬
13 名稱就緒狀態(tài)重新啟動(dòng)年齡 IP 節(jié)點(diǎn)提名節(jié)點(diǎn)就緒門(mén)
14 scheduler-nodeselector-deploy-79455db454-745ph    1 / 1     運(yùn)行   0           19s    10.244。4.154    k8s-node01 <none> <none>
 15 scheduler-nodeselector-deploy-79455db454-bmjvd    1 / 1     運(yùn)行   0           19s    10.244。4.151    k8s-node01 <none> <none>
 16調(diào)度程序-nodeselector-deploy-79455db454-g5cg2    1 /1     運(yùn)行   0           19s    10.244。4.153 k8s    -node01 <none> <none>
 17 scheduler-nodeselector-deploy-79455db454-hw8jv    1 / 1     運(yùn)行   0           19s    10.244。4.152    k8s-node01 <none> <none>
 18 scheduler-nodeselector-deploy-79455db454-zrt8d    1 / 1     運(yùn)行   0           19s    10.244。4.155    k8s-node01 <無(wú)> <無(wú)>

由上可見(jiàn),所有pod都被調(diào)度到了k8s-node01節(jié)點(diǎn)。當(dāng)然如果其他節(jié)點(diǎn)也有disk-type=ssd 標(biāo)簽,那么pod也會(huì)調(diào)度到這些節(jié)點(diǎn)上。

 

當(dāng)nodeSelector標(biāo)簽不存在

要運(yùn)行的yaml文件

1 [root@k8s-master scheduler]# pwd 
2 /root/k8s_practice/ scheduler
 3 [root@k8s- master scheduler]# 
 4 [root@k8s-master scheduler]# cat scheduler_nodeSelector_02.yaml 
 5 apiVersion:apps/ v1
 6種 :部署
7 元數(shù)據(jù):
 8   名稱:scheduler-nodeselector-部署
9   標(biāo)簽:
 10     應(yīng)用程序:nodeselector-部署
11 規(guī)范:
 12   副本:5 
13   選擇器:
 14      matchLabels:
 15       app: myapp
16   template:
17     metadata:
18       labels:
19         app: myapp
20     spec:
21       containers:
22       - name: myapp-pod
23         image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1
24         imagePullPolicy: IfNotPresent
25         ports:
26           - containerPort: 80
27       # 指定節(jié)點(diǎn)標(biāo)簽選擇,且標(biāo)簽不存在
28       nodeSelector:
29         service-type: web

 

運(yùn)行yaml文件并查看信息

1 [root@k8s-master scheduler]# kubectl apply -f scheduler_nodeSelector_02.yaml 
  2 deployment.apps/scheduler-nodeselector- deploy created
  3 [root@k8s- master scheduler]# 
  4 [root@k8s-master scheduler]# kubectl get deploy -o wide
  5 NAME READY Up- TO- DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
  6 scheduler-nodeselector-deploy     0 / 5      5             0             26s myapp-pod registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1 app= myapp
  7 [root@k8s -主調(diào)度程序]# 
  8[root@k8s-master scheduler]# kubectl get rs -o wide
  9  NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
  10 scheduler-nodeselector-deploy-799d748db6     5          5          0         30s myapp-pod registry .cn-beijing.aliyuncs.com/google_registry /myapp:v1 app=myapp,pod-template-hash= 799d748db6
  11 [root@k8s- master scheduler]# 
  12 [root@k8s-master scheduler]# kubectl get pod -o寬
13  NAME READY STATUS RESTARTS AGE IP Node NOMINATED節(jié)點(diǎn)就緒
 門(mén)14 scheduler-nodeselector-deploy-799d748db6-92mqj     0 / 1      待定    0            40s <none> <none> <none> <none>
  15 scheduler-nodeselector-deploy-799d748db6-c2w25     0 / 1       Pending     0            40s <none> <none> <none> <none>
  16 scheduler-nodeselector-deploy-799d748db6 -c8tlx     0 / 1      等待    0            40s <無(wú)> <無(wú)> <無(wú)>
<無(wú)> 17 scheduler-nodeselector-deploy-799d748db6-tc5n7     0 / 1       Pending     0            40s <none> <none> <none> <none>
  18 scheduler-nodeselector-deploy-799d748db6-z8c57     0 / 1       Pending     0            40s <none> <無(wú)> <無(wú)> <無(wú)>

由上可見(jiàn),如果nodeSelector匹配的標(biāo)簽不存在,則容器將不會(huì)運(yùn)行,一直處于Pending 狀態(tài)。

 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多