亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

k8s調度器

發布時間:2020-08-12 10:29:13 來源:ITPUB博客 閱讀:129 作者:z597011036 欄目:云計算

節點硬親和度:Pod調度時必須滿足規劃,如不滿足Pod狀態將是Penging狀態。

節點軟親和度:Pod調度時先按規則進行調度,如不滿足規則也會找一個不匹配的節點運行。

Pod硬親和度,軟親和度與節點硬親和度,軟親和度相似。

1.節點硬親和度(節點不滿足規則)

[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"]}   --節點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節點不滿足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.節點硬親和度(節點滿足規則)

[root@k8s01 yaml]# kubectl label node k8s02 zone=one     --在k8s02節點創建標簽

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.節點軟親和度

[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會調度到zone標簽,one值這個節點上
            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    --滿足標簽可創建,不滿足也可創建

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硬親和度(節點不滿足規則)

[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硬親和度 (節點滿足規則)

[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       --創建的新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軟親和度也可創建
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對像,不能調度到當前節點,強制性。

PreferNoSchedule:新Pod盡量不調度到此節點,若無其它節點可以調度,也允許使用當前節點調度,柔和性。

NoExecute:新Pod不能調度到當前節點,如果當前節點存在Pod也會被驅逐,強制性。

[root@k8s01 yaml]# kubectl  describe node k8s02 | grep -i taints     --查看污點
Taints:             <none>
[root@k8s01 yaml]# kubectl taint node k8s02 node-type=production:NoSchedule    --為k8s02節點打污點

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節點已打污點,所以不能調度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. 驅逐節點上的Pod

[root@k8s01 yaml]# kubectl cordon k8s03    --將新創建的pod不能調度到k8s03節點,以前的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     --釋放調度規則
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節點上的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節點的Pod全部轉移到其它節點上
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     --恢復調度
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]#

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

扬州市| 荣昌县| 乌兰察布市| 洛浦县| 天祝| 昌江| 临桂县| 武胜县| 姜堰市| 夏河县| 泰和县| 云龙县| 南京市| 平利县| 苏尼特左旗| 吴堡县| 肃南| 青龙| 汝州市| 平南县| 华亭县| 崇文区| 锦州市| 合肥市| 铁岭市| 来安县| 泗洪县| 青浦区| 塔河县| 门源| 仙桃市| 汝南县| 类乌齐县| 自贡市| 南平市| 鹿泉市| 鄂伦春自治旗| 如东县| 澎湖县| 东丽区| 恭城|