節(jié)點硬親和度:Pod調(diào)度時必須滿足規(guī)劃,如不滿足Pod狀態(tài)將是Penging狀態(tài)。
十載的公安網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整公安建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)建站從事“公安網(wǎng)站設(shè)計”,“公安網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
節(jié)點軟親和度:Pod調(diào)度時先按規(guī)則進行調(diào)度,如不滿足規(guī)則也會找一個不匹配的節(jié)點運行。
Pod硬親和度,軟親和度與節(jié)點硬親和度,軟親和度相似。
1.節(jié)點硬親和度(節(jié)點不滿足規(guī)則)
[root@k8s01 yaml]# cat pod-affinity01.yaml
apiVersion: v1 kind: Pod metadata: name: pod-01 spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - {key: zone,operator: In,values: ["one"]} --節(jié)點zone(鍵)標簽必須是one(值) containers: - name: pod-01 image: nginx:latest imagePullPolicy: Never
[root@k8s01 yaml]# kubectl apply -f pod-affinity01.yaml
pod/pod-01 created
[root@k8s01 yaml]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
pod-01 0/1 Pending 0 103s <none> --node節(jié)點不滿足pod標簽
[root@k8s01 yaml]# kubectl describe pods pod-01
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling <unknown> default-scheduler 0/3 nodes are available: 3 node(s) didn't match node selector.
Warning FailedScheduling <unknown> default-scheduler 0/3 nodes are available: 3 node(s) didn't match node selector.
[root@k8s01 yaml]#
- matchExpressions: - {key: zone,operator: In,values: ["one"]} --zone是鍵,operator:是表達式,one是值 - {key: zone,operator: In,values: ["one","two"]} --In 是包含 - {key: ssd,operator: Exists,values: []} --Exists是存在
2.節(jié)點硬親和度(節(jié)點滿足規(guī)則)
[root@k8s01 yaml]# kubectl label node k8s02 zone=one --在k8s02節(jié)點創(chuàng)建標簽
node/k8s02 labeled
[root@k8s01 yaml]# kubectl get pods --show-labels -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
pod-01 1/1 Running 0 6m13s 10.244.1.37 k8s02 <none> <none> <none>
[root@k8s01 yaml]#
3.節(jié)點軟親和度
[root@k8s01 yaml]# cat pod-affinity02.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: pod-02 spec: replicas: 3 selector: matchLabels: app: myapp template: metadata: name: myapp-pod labels: app: myapp spec: affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 60 --60%的Pod會調(diào)度到zone標簽,one值這個節(jié)點上 preference: matchExpressions: - {key: zone,operator: In,values: ["one"]} containers: - name: pod-02 image: nginx:latest imagePullPolicy: Never
[root@k8s01 yaml]# kubectl apply -f pod-affinity02.yaml
deployment.apps/pod-02 created
[root@k8s01 yaml]# kubectl get pods --show-labels -o wide --滿足標簽可創(chuàng)建,不滿足也可創(chuàng)建
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
pod-02-77d87986b-9bzg5 1/1 Running 0 16s 10.244.1.39 k8s02 <none> <none> app=myapp,pod-template-hash=77d87986b
pod-02-77d87986b-dckjq 1/1 Running 0 16s 10.244.2.42 k8s03 <none> <none> app=myapp,pod-template-hash=77d87986b
pod-02-77d87986b-z7v47 1/1 Running 0 16s 10.244.1.38 k8s02 <none> <none> app=myapp,pod-template-hash=77d87986b
[root@k8s01 yaml]#
4. Pod硬親和度(節(jié)點不滿足規(guī)則)
[root@k8s01 yaml]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx 1/1 Running 0 4s
app=web
[root@k8s01 yaml]# cat pod-affinity03.yaml
apiVersion: v1 kind: Pod metadata: name: pod-01 spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - {key: app,operator: In,values: ["web1"]} --標簽值不滿足 topologyKey: kubernetes.io/hostname containers: - name: pod-01 image: nginx:latest imagePullPolicy: Never
[root@k8s01 yaml]# kubectl apply -f pod-affinity03.yaml
pod/pod-01 created
[root@k8s01 yaml]# kubectl get pods --show-labels -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
nginx 1/1 Running 0 8m9s 10.244.1.42 k8s02 <none> <none> app=web
pod-01 0/1
Pending 0 28s <none> <none> <none> <none> <none>
[root@k8s01 yaml]#
5.Pod硬親和度 (節(jié)點滿足規(guī)則)
[root@k8s01 yaml]# kubectl get pods --show-labels --查看pod標簽
NAME READY STATUS RESTARTS AGE LABELS
nginx 1/1 Running 0 4s
app=web
[root@k8s01 yaml]# cat pod-affinity04.yaml
apiVersion: v1 kind: Pod metadata: name: pod-01 spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - {key: app,operator: In,values: ["web"]} topologyKey: kubernetes.io/hostname containers: - name: pod-01 image: nginx:latest imagePullPolicy: Never
[root@k8s01 yaml]# kubectl apply -f pod-affinity04.yaml
pod/pod-01 created
[root@k8s01 yaml]# kubectl get pods --show-labels -o wide --創(chuàng)建的新Pod會找app=web的標簽
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
nginx 1/1 Running 0 4m14s 10.244.1.42
k8s02 <none> <none> app=web
pod-01 1/1
Running 0 17s 10.244.1.43
k8s02 <none> <none> <none>
[root@k8s01 yaml]#
6.Pod軟親和度
[root@k8s01 yaml]# kubectl get pods --show-labels -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
nginx 1/1 Running 0 14m 10.244.1.42 k8s02 <none> <none> app=web
[root@k8s01 yaml]# cat pod-affinity04.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: pod-02 spec: replicas: 3 selector: matchLabels: app: myapp template: metadata: name: myapp-pod labels: app: myapp spec: affinity: podAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 60 podAffinityTerm: labelSelector: matchExpressions: - {key: app,operator: In,values: ["web12"]} topologyKey: zone containers: - name: pod-02 image: nginx:latest imagePullPolicy: Never
[root@k8s01 yaml]# kubectl get pods --show-labels -o wide --不滿足Pod軟親和度也可創(chuàng)建
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
nginx 1/1 Running 0 16m 10.244.1.42 k8s02 <none> <none> app=web
pod-02-6f96fbfdf-52gbf 1/1 Running 0 11s 10.244.2.43
k8s03 <none> <none> app=myapp,pod-template-hash=6f96fbfdf
pod-02-6f96fbfdf-dl5z5 1/1 Running 0 11s 10.244.1.44
k8s02 <none> <none> app=myapp,pod-template-hash=6f96fbfdf
pod-02-6f96fbfdf-f8bzn 1/1 Running 0 11s 10.244.0.55
k8s01 <none> <none> app=myapp,pod-template-hash=6f96fbfdf
[root@k8s01 yaml]#
7.定義污點和容忍度
NoSchedule:不能容忍此污點的新Pod對像,不能調(diào)度到當前節(jié)點,強制性。
PreferNoSchedule:新Pod盡量不調(diào)度到此節(jié)點,若無其它節(jié)點可以調(diào)度,也允許使用當前節(jié)點調(diào)度,柔和性。
NoExecute:新Pod不能調(diào)度到當前節(jié)點,如果當前節(jié)點存在Pod也會被驅(qū)逐,強制性。
[root@k8s01 yaml]# kubectl describe node k8s02 | grep -i taints --查看污點
Taints: <none>
[root@k8s01 yaml]# kubectl taint node k8s02 node-type=production:NoSchedule --為k8s02節(jié)點打污點
node/k8s02 tainted
[root@k8s01 yaml]# kubectl describe node k8s02 | grep -i taints
Taints: node-type=production:NoSchedule
[root@k8s01 yaml]# cat pod-affinity05.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: pod-02 spec: replicas: 3 selector: matchLabels: app: myapp template: metadata: name: myapp-pod labels: app: myapp spec: containers: - name: pod-02 image: nginx:latest imagePullPolicy: Never
[root@k8s01 yaml]# kubectl apply -f pod-affinity05.yaml
deployment.apps/pod-02 created
[root@k8s01 yaml]# kubectl get pods -o wide --show-labels --k8s02節(jié)點已打污點,所以不能調(diào)度Pod對像
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
pod-02-5c54dc6489-j7tsh 1/1 Running 0 29s 10.244.0.56
k8s01 <none> <none> app=myapp,pod-template-hash=5c54dc6489
pod-02-5c54dc6489-sk5dm 1/1 Running 0 29s 10.244.2.44
k8s03 <none> <none> app=myapp,pod-template-hash=5c54dc6489
pod-02-5c54dc6489-sn5wd 1/1 Running 0 29s 10.244.2.45
k8s03 <none> <none> app=myapp,pod-template-hash=5c54dc6489
[root@k8s01 yaml]
8.刪除污點
[root@k8s01 yaml]# kubectl taint node k8s02 node-type:NoSchedule- --刪除 NoSchedule污點
node/k8s02 untainted
[root@k8s01 yaml]# kubectl taint node k8s02 node-type=production:PreferNoSchedule --打上污點
node/k8s02 tainted
[root@k8s01 yaml]# kubectl describe node k8s02 | grep -i node-type
Taints: node-type=production:PreferNoSchedule
[root@k8s01 yaml]# kubectl taint node k8s02 node-type:PreferNoSchedule- --刪除
PreferNoSchedule污點
node/k8s02 untainted
[root@k8s01 yaml]# kubectl describe node k8s02 | grep -i node-type
[root@k8s01 yaml]# kubectl taint node k8s02 node-type- --刪除所有污點
node/k8s02 untainted
[root@k8s01 yaml]# kubectl describe node k8s02 | grep -i node-type
[root@k8s01 yaml]#
9. 驅(qū)逐節(jié)點上的Pod
[root@k8s01 yaml]# kubectl cordon k8s03 --將新創(chuàng)建的pod不能調(diào)度到k8s03節(jié)點,以前的Pod不受影響。
node/k8s03 cordoned
[root@k8s01 yaml]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s01 Ready master 71d v1.16.0
k8s02 Ready <none> 70d v1.16.0
k8s03 Ready,
SchedulingDisabled <none> 30d v1.16.0
[root@k8s01 yaml]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-02-5c54dc6489-442kx 1/1 Running 0 12m 10.244.2.48
k8s03 <none> <none>
pod-02-5c54dc6489-92l8m 1/1 Running 0 12m 10.244.2.49
k8s03 <none> <none>
pod-02-5c54dc6489-k4bc7 1/1 Running 0 12m 10.244.0.58 k8s01 <none> <none>
[root@k8s01 yaml]# kubectl uncordon k8s03 --釋放調(diào)度規(guī)則
node/k8s03 uncordoned
[root@k8s01 yaml]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s01 Ready master 71d v1.16.0
k8s02 Ready <none> 70d v1.16.0
k8s03 Ready <none> 30d v1.16.0
[root@k8s01 yaml]# kubectl drain k8s03 --ignore-daemonsets --去除k8s03節(jié)點上的Pod
node/k8s03 already cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/kube-flannel-ds-amd64-cg795, kube-system/kube-proxy-h5dkf
evicting pod "pod-02-5c54dc6489-92l8m"
evicting pod "pod-02-5c54dc6489-442kx"
pod/pod-02-5c54dc6489-92l8m evicted
pod/pod-02-5c54dc6489-442kx evicted
node/k8s03 evicted
[root@k8s01 yaml]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s01 Ready master 71d v1.16.0
k8s02 Ready <none> 70d v1.16.0
k8s03 Ready,
SchedulingDisabled <none> 30d v1.16.0
[root@k8s01 yaml]# kubectl get pods -o wide --以前k8s03節(jié)點的Pod全部轉(zhuǎn)移到其它節(jié)點上
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-02-5c54dc6489-k4bc7 1/1 Running 0 14m 10.244.0.58
k8s01 <none> <none>
pod-02-5c54dc6489-mxk46 1/1 Running 0 25s 10.244.1.46
k8s02 <none> <none>
pod-02-5c54dc6489-vmb8l 1/1 Running 0 25s 10.244.1.45
k8s02 <none> <none>
[root@k8s01 yaml]# kubectl uncordon k8s03 --恢復(fù)調(diào)度
node/k8s03 uncordoned
[root@k8s01 yaml]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s01 Ready master 71d v1.16.0
k8s02 Ready <none> 70d v1.16.0
k8s03 Ready <none> 30d v1.16.0
[root@k8s01 yaml]#
分享名稱:k8s調(diào)度器
瀏覽地址:http://aaarwkj.com/article6/pdicig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、域名注冊、網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計、網(wǎng)站導(dǎo)航、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)