86、pod部署策略

一、集群的调度

集群的调度:

怎么把pod部署到节点的方法。

1.1、调度的过程:

scheduler是集群的调度器,主要任务就是把pod部署到节点上。

1.2、自动调度:

1、公平,保证每个可用的节点都可以部署pod

2、资源的高效利用,集群当中的资源可用被最大化的使用

3、效率,调度的性能要好,能够对大批量的pod完成调度工作。

4、灵活(自定义),用户需要根据自己的需求进行控制,可以满足。

1.3、调度约束机制:

list-watch机制来进行每个组件的协作,保持数据同步,组件之间的解耦。

list-watchwatch:k8s当中的监听get:获取资源

apiserver和组件之间的watch监听机制:

在这里插入图片描述

二、调度过程:

2.1、默认算法有两种:

1、预算策略

1、预算策略:先对节点的条件进行过滤

pod的资源适应性:节点是否有资源能够满足pod请求的资源

pod的主机适应性:如果指定了节点,检查集群中是否有满足要求的节点可供部署

pod的主机端口适应性:检查节点上使用的端口是否与pod请求的端口冲突

pod与主机磁盘的适应性:每个pod的挂载卷不能冲突。

如果预算条件不满足,pod会进行pending状态

2、优选策略

2、优选策略:根据过滤条件选择一条最优的节点

最低请求优先级:通过计算节点上cpu和内存的使用率,确定节点的权重。使用率越低权重越大,越会被选中作为部署节点。

倾向于选择资源占用较少的节点。

平衡资源分配:cpu和内存的使用率,确定节点的权重。按cpu和内存之间比率,使用率的比率。cpu和内存比越接近1。

A 50% 50% 优先级高

B 10% 20%

镜像本地性优先级:如果节点在本地已经有了需要的镜像,分配的概率更大。

随调度部署nginx1
[root@master01 k8s-yaml]# vim test11.yamlapiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22[root@master01 k8s-yaml]# kubectl apply -f test11.yaml 
deployment.apps/nginx1 created
[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-d7tdz   1/1     Running   0          12s   10.244.2.137   node02   <none>           <none>
nginx1-654cb56c4-mp8zz   1/1     Running   0          14s   10.244.2.136   node02   <none>           <none>
nginx1-654cb56c4-qnlxw   1/1     Running   0          13s   10.244.1.98    node01   <none>           <none>

2.2、用户定制节点部署:(重要)

1、强制性节点调度:

nodeName强制性的选择一个节点,不再需要调度器和算法了。之间部署即可。

[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,test1=a,test2=b,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b
强制性布置在node01
[root@master01 k8s-yaml]# vim test11.yamlapiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22nodeName: node01[root@master01 k8s-yaml]# kubectl apply -f test11.yaml --force[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-95bf57c7f-nrbjb   1/1     Running   0          48s   10.244.1.101   node01   <none>           <none>
nginx1-95bf57c7f-phxx5   1/1     Running   0          50s   10.244.1.99    node01   <none>           <none>
nginx1-95bf57c7f-zl78g   1/1     Running   0          49s   10.244.1.100   node01   <none>           <none>

2.3、查看节点的标签

[root@master01 k8s-yaml]# kubectl get nodes --show-labels
标签的格式是键值对
一个节点可以有多个标签,每个以逗号隔开[root@master01 k8s-yaml]# kubectl label nodes node01 test=a      ##增加标签
node/node01 labeled[root@master01 k8s-yaml]# kubectl label nodes node01 test=b --overwrite   ##改标签
node/node01 labeled[root@master01 k8s-yaml]# kubectl label nodes node01 test-         ##删除标签
node/node01 labeled

自定义标签

[root@master01 k8s-yaml]# kubectl label nodes node01 test1=a
node/node01 labeled
[root@master01 k8s-yaml]# kubectl label nodes node02 test2=b
node/node02 labeled

2.4、根据节点的标签来进行部署。匹配机制,只要标签匹配都可以部署

根据节点的标签来进行部署。匹配机制,只要标签匹配都可以部署。

问题:标签选择节点是否需要调度器和算法

需要调度器和算法来进行分配的。

[root@master01 k8s-yaml]# vim test12.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22nodeSelector:test2: b[root@master01 k8s-yaml]# kubectl label nodes node01 test3=b
node/node01 labeled
[root@master01 k8s-yaml]# kubectl apply -f test12.yaml 
[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-76bd776789-74j2f   1/1     Running   0          21s   10.244.2.138   node02   <none>           <none>
nginx1-76bd776789-qkjtc   1/1     Running   0          19s   10.244.2.139   node02   <none>           <none>
nginx1-76bd776789-z7885   1/1     Running   0          18s   10.244.2.140   node02   <none>           <none>[root@master01 k8s-yaml]# kubectl label nodes node01 test2=b[root@master01 k8s-yaml]# vim test12.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22nodeSelector:test2: b
[root@master01 k8s-yaml]# kubectl apply -f test12.yaml 
[root@master01 k8s-yaml]# kubectl get pod -o wide
[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-76bd776789-5dssm   1/1     Running   0          9s    10.244.2.141   node02   <none>           <none>
nginx1-76bd776789-mpk42   1/1     Running   0          9s    10.244.1.102   node01   <none>           <none>
nginx1-76bd776789-zpbkp   1/1     Running   0          9s    10.244.2.142   node02   <none>           <none>##同时都有自定义标签,随机部署在两个节点上

三、亲和性

节点亲和性:node Affinity

pod亲和性:pod Affinity

软策略和硬策略:
软策略:

preferredDuringSchedulingIgnoredDuringExecution

软策略在选择节点尽量满足部署的条件,非条件也可以部署。

硬策略:

requiredDuringSchedulingIgnoredDuringExecution

硬策略:必须满足指定的节点条件,否则pending

1、条件不满足,肯定pending

2、条件满足,调度器即可生效

3、需要调度器的分配,不同节点可以有相同的标签。需要调度器分配。

根据节点标签和pod的标签来进行选择:

键值的运算关系:
1、In 在  匹配 =2、Notin 不在 不等于  ,逻辑非3、Gt 大于4、Lt 小于5、Exists 存在6、DoesNotExist 不存在

3.1、亲和性:

topologkey 定义节点的拓扑域,用来反映pod和节点之间的关系。

硬策略

[root@master01 k8s-yaml]# vim test12.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22affinity:
#选择亲和性的字段nodeAffinity:
#节点亲和性requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: test1operator: Invalues:- a
#节点亲和性的硬策略,表示必须选择带有标签的值是test1=a
[root@master01 k8s-yaml]# kubectl apply -f test12.yaml [root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-8f7b9d885-4ds5z   1/1     Running   0          21s   10.244.1.103   node01   <none>           <none>
nginx1-8f7b9d885-c9zbc   1/1     Running   0          19s   10.244.1.105   node01   <none>           <none>
nginx1-8f7b9d885-cwgdj   1/1     Running   0          20s   10.244.1.104   node01   <none>           <none>[root@master01 k8s-yaml]# vim test12.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22affinity:
#选择亲和性的字段nodeAffinity:
#节点亲和性requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: test1operator: NotInvalues:- a
#节点亲和性的硬策略,表示必须选择带有标签的值不是test1=a[root@master01 k8s-yaml]# kubectl apply -f test12.yaml
[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-7f4db4ff6b-4pg5w   1/1     Running   0          75s   10.244.2.145   node02   <none>           <none>
nginx1-7f4db4ff6b-dslv4   1/1     Running   0          76s   10.244.2.143   node02   <none>           <none>
nginx1-7f4db4ff6b-lmrjk   1/1     Running   0          76s   10.244.2.144   node02   <none>           <none>试验:[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,test1=a,test2=b,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test1=a,test2=b[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                      READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
nginx1-7f4db4ff6b-99l2r   0/1     Pending   0          10s   <none>   <none>   <none>           <none>
nginx1-7f4db4ff6b-gjfkd   0/1     Pending   0          10s   <none>   <none>   <none>           <none>
nginx1-7f4db4ff6b-hsks5   0/1     Pending   0          10s   <none>   <none>   <none>           <none>[root@master01 k8s-yaml]# kubectl label nodes node02 test1-
node/node02 labeled
[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,test1=a,test2=b,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-7f4db4ff6b-99l2r   1/1     Running   0          93s   10.244.2.146   node02   <none>           <none>
nginx1-7f4db4ff6b-gjfkd   1/1     Running   0          93s   10.244.2.147   node02   <none>           <none>
nginx1-7f4db4ff6b-hsks5   1/1     Running   0          93s   10.244.2.148   node02   <none>           <none>条件满足,不需要强制重启,[root@master01 k8s-yaml]# kubectl get pod -o wide即可

软策略:

单个权重
[root@master01 k8s-yaml]# vim test12.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22affinity:
#选择亲和性的字段nodeAffinity:
#节点亲和性preferredDuringSchedulingIgnoredDuringExecution:- weight: 1preference:matchExpressions:- key: test1operator: NotInvalues:- a
#节点的亲和性的软策略,希望部署到不包含test1=a的标签节点。
[root@master01 k8s-yaml]# kubectl apply -f test12.yaml
[root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-7b45d5b8f-hwxgj   1/1     Running   0          17s   10.244.2.149   node02   <none>           <none>
nginx1-7b45d5b8f-x24j4   1/1     Running   0          15s   10.244.2.150   node02   <none>           <none>
nginx1-7b45d5b8f-zbdvq   1/1     Running   0          14s   10.244.1.106   node01   <none>           <none>##软限制,只能做一点点资源调度,不能强制##podAffinity[root@master01 k8s-yaml]# vim test13.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx2name: nginx2
spec:replicas: 3selector:matchLabels:app: nginx2template:metadata:labels:app: nginx2spec:containers:- name: nginximage: nginx:1.22affinity:podAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 1podAffinityTerm:labelSelector:matchExpressions:- key: appoperator: Invalues:- nginx1topologyKey: test3[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,memory=1000,test1=a,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b,xy102=98[root@master01 k8s-yaml]# kubectl apply -f test13.yaml [root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                      READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-7t69j    1/1     Running   0          153m    10.244.1.110   node01   <none>           <none>
nginx1-654cb56c4-d8q56    1/1     Running   0          153m    10.244.1.109   node01   <none>           <none>
nginx1-654cb56c4-q89zj    1/1     Running   0          153m    10.244.2.152   node02   <none>           <none>
nginx2-6b6584f58f-2dr9n   1/1     Running   0          4m27s   10.244.1.120   node01   <none>           <none>
nginx2-6b6584f58f-7vntk   1/1     Running   0          4m27s   10.244.1.121   node01   <none>           <none>
nginx2-6b6584f58f-zbhv5   1/1     Running   0          4m27s   10.244.2.186   node02   <none>           <none>

多个权重

[root@master01 k8s-yaml]# vim test12.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22affinity:
#选择亲和性的字段nodeAffinity:
#节点亲和性preferredDuringSchedulingIgnoredDuringExecution:- weight: 1preference:matchExpressions:- key: test1operator: NotInvalues:- apreferredDuringSchedulingIgnoredDuringExecution:- weight: 1preference:matchExpressions:- key: test2operator: NotInvalues:- b#多个软策略以权重来进行分配,权重高的,优先级大[root@master01 k8s-yaml]# kubectl apply -f test12.yaml
deployment.apps/nginx1 configured
[root@master01 k8s-yaml]# kubectl get pod -o wide
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-698c85f477-475q8   1/1     Running   0          17s   10.244.1.107   node01   <none>           <none>
nginx1-698c85f477-jssbs   1/1     Running   0          15s   10.244.2.151   node02   <none>           <none>
nginx1-698c85f477-pc9m7   1/1     Running   0          14s   10.244.1.108   node01   <none>           <none>#多个软策略以权重来进行分配,权重高的,优先级大,weight=2>weight=1,使得在node01部署较多,不是绝对部署在node01
[root@master01 k8s-yaml]# vim test12.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx1name: nginx1
spec:replicas: 3selector:matchLabels:app: nginx1template:metadata:labels:app: nginx1spec:containers:- name: nginximage: nginx:1.22affinity:
#选择亲和性的字段nodeAffinity:
#节点亲和性preferredDuringSchedulingIgnoredDuringExecution:- weight: 1preference:matchExpressions:- key: test1operator: NotInvalues:- arequiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: test2operator: NotInvalues:- b
#如果已经有硬策略,一般不需要声明软策略。[root@master01 k8s-yaml]# kubectl apply -f test12.yaml
deployment.apps/nginx1 configured
[root@master01 k8s-yaml]# kubectl get pod -o wide
#匹配的pod的标签是app=nginx1,且节点上包含标签名是test2
[root@master01 k8s-yaml]# kubectl describe deployments.apps nginx1 Labels:                 app=nginx1[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,test1=a,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b[root@master01 k8s-yaml]# vim test13.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx2name: nginx2
spec:replicas: 3selector:matchLabels:app: nginx2template:metadata:labels:app: nginx2spec:containers:- name: nginximage: nginx:1.22affinity:podAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:#根据标签进行选择matchExpressions:- key: appoperator: Invalues:- nginx1topologyKey: test2
#匹配的pod的标签是app=nginx1,且节点上包含标签名是test2   [root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                     READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-7t69j   1/1     Running   0          4m36s   10.244.1.110   node01   <none>           <none>
nginx1-654cb56c4-d8q56   1/1     Running   0          4m36s   10.244.1.109   node01   <none>           <none>
nginx1-654cb56c4-q89zj   1/1     Running   0          4m36s   10.244.2.152   node02   <none>           <none>
nginx2-8c5695d94-jx7sr   1/1     Running   0          4s      10.244.2.155   node02   <none>           <none>
nginx2-8c5695d94-qtcf6   1/1     Running   0          4s      10.244.2.153   node02   <none>           <none>
nginx2-8c5695d94-xwg6b   1/1     Running   0          4s      10.244.2.154   node02   <none>           <none>

3.2、反亲和性:

pod反亲和性 pod Anti-Affinity

[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,test1=a,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b[root@master01 k8s-yaml]# vim test13.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx2name: nginx2
spec:replicas: 3selector:matchLabels:app: nginx2template:metadata:labels:app: nginx2spec:containers:- name: nginximage: nginx:1.22affinity:podAntiAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:#根据标签进行选择matchExpressions:- key: appoperator: Invalues:- nginx1topologyKey: test2##
[root@master01 k8s-yaml]# kubectl apply -f test13.yaml 
[root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-7t69j   1/1     Running   0          13m   10.244.1.110   node01   <none>           <none>
nginx1-654cb56c4-d8q56   1/1     Running   0          13m   10.244.1.109   node01   <none>           <none>
nginx1-654cb56c4-q89zj   1/1     Running   0          13m   10.244.2.152   node02   <none>           <none>
nginx2-5784d9dcb-bnxcb   1/1     Running   0          72s   10.244.1.111   node01   <none>           <none>
nginx2-5784d9dcb-f6pvb   1/1     Running   0          70s   10.244.1.112   node01   <none>           <none>
nginx2-5784d9dcb-rpsjk   1/1     Running   0          69s   10.244.1.113   node01   <none>           <none>#只能部署在pod的标签不是app=nginx1且节点的标签名不能有test2#其实在pod的亲和性当中,起决定作用的是拓扑域的标签。Events:Type     Reason            Age                From               Message----     ------            ----               ----               -------Warning  FailedScheduling  22m (x2 over 22m)  default-scheduler  0/3 nodes are available: 3 node(s) didn't match pod affinity/anti-affinity, 3 node(s) didn't match pod anti-affinity rules.Normal   Scheduled         22m                default-scheduler  Successfully assigned default/nginx2-5bdc766cf7-sk69d to master01#能够部署的原因在于调度器,调度器的核心是为了部署pod,只要能够部署,调度器有可能会忽略规则进行部署,既然有规则,调度器依然会部署
#资源不足的情况下,为了pod能够部署,调度器极有可能忽略所有的限制。

软策略:倾向性,尽可能的满足条件----更多的,尽量把资源调度到需要的节点

硬策略:必须要满足条件。-----特殊情况,节点故障,但是有业务要更新,强制性的把资源调度到指定的节点。

[root@master01 k8s-yaml]# vim test13.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx2name: nginx2
spec:replicas: 3selector:matchLabels:app: nginx2template:metadata:labels:app: nginx2spec:containers:- name: nginximage: nginx:1.22affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: test3operator: NotInvalues:- b[root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-7t69j    1/1     Running   0          24m   10.244.1.110   node01   <none>           <none>
nginx1-654cb56c4-d8q56    1/1     Running   0          24m   10.244.1.109   node01   <none>           <none>
nginx1-654cb56c4-q89zj    1/1     Running   0          24m   10.244.2.152   node02   <none>           <none>
nginx2-5d77fdc494-2lxc6   1/1     Running   0          39s   10.244.2.157   node02   <none>           <none>
nginx2-5d77fdc494-7hswd   1/1     Running   0          38s   10.244.2.158   node02   <none>           <none>
nginx2-5d77fdc494-9ckqj   1/1     Running   0          40s   10.244.2.156   node02   <none>           <none>

Gt用法

[root@master01 k8s-yaml]# kubectl label nodes node01 memory=1000
node/node01 labeled
[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,memory=1000,test1=a,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b[root@master01 k8s-yaml]# vim test13.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx2name: nginx2
spec:replicas: 3selector:matchLabels:app: nginx2template:metadata:labels:app: nginx2spec:containers:- name: nginximage: nginx:1.22affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: memoryoperator: Gtvalues:- "500"
[root@master01 k8s-yaml]# kubectl apply -f test13.yaml [root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-7t69j    1/1     Running   0          43m   10.244.1.110   node01   <none>           <none>
nginx1-654cb56c4-d8q56    1/1     Running   0          43m   10.244.1.109   node01   <none>           <none>
nginx1-654cb56c4-q89zj    1/1     Running   0          43m   10.244.2.152   node02   <none>           <none>
nginx2-79b79dd568-gpjx5   1/1     Running   0          56s   10.244.1.116   node01   <none>           <none>
nginx2-79b79dd568-rhjs4   1/1     Running   0          58s   10.244.1.114   node01   <none>           <none>
nginx2-79b79dd568-trn54   1/1     Running   0          57s   10.244.1.115   node01   <none>           <none>
[root@master01 k8s-yaml]# vim test13.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx2name: nginx2
spec:replicas: 3selector:matchLabels:app: nginx2template:metadata:labels:app: nginx2spec:containers:- name: nginximage: nginx:1.22affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: memoryoperator: DoesNotExist
[root@master01 k8s-yaml]# kubectl apply -f test13.yaml [root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-7t69j    1/1     Running   0          46m   10.244.1.110   node01   <none>           <none>
nginx1-654cb56c4-d8q56    1/1     Running   0          46m   10.244.1.109   node01   <none>           <none>
nginx1-654cb56c4-q89zj    1/1     Running   0          46m   10.244.2.152   node02   <none>           <none>
nginx2-585c559d74-ccqt6   1/1     Running   0          19s   10.244.2.159   node02   <none>           <none>
nginx2-585c559d74-k4vxw   1/1     Running   0          18s   10.244.2.160   node02   <none>           <none>
nginx2-585c559d74-zv6z5   1/1     Running   0          17s   10.244.2.161   node02   <none>           <none>

四、作业:

1、实现pod的探针:

就绪探针

tcpSocket

2、挂载,容器 /usr/share/nginx/html

​ 节点 /opt/html

3、node的亲和性 尽量部署在node01

4、pod的亲和性,尽量部署包含有app=nginx1的pod且目标签名是xy102的节点。

5、软策略选择标签名包含xy102, 值小于100。

[root@master01 k8s-yaml]# kubectl get nodes --show-labels
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,memory=1000,test1=a,test3=b
node02     Ready    <none>                 8d    v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b,xy102=98[root@master01 k8s-yaml]# vim test5.yaml apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx2name: nginx2
spec:replicas: 12selector:matchLabels:app: nginx2template:metadata:labels:app: nginx2spec:containers:- name: nginximage: nginx:1.22volumeMounts:- name: data-vmountPath: /usr/share/nginx/htmlreadinessProbe:tcpSocket:port: 80volumes:- name: data-vhostPath:path: /opt/htmltype: DirectoryOrCreateaffinity:
#选择亲和性的字段nodeAffinity:
#节点亲和性preferredDuringSchedulingIgnoredDuringExecution:- weight: 3preference:matchExpressions:- key: test1operator: Invalues:- apreferredDuringSchedulingIgnoredDuringExecution:- weight: 1preference:matchExpressions:- key: xy102operator: Ltvalues:- "100"podAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 1podAffinityTerm:labelSelector:matchExpressions:- key: appoperator: Invalues:- nginx1topologyKey: xy102[root@master01 k8s-yaml]# kubectl apply -f test5.yaml[root@master01 k8s-yaml]# kubectl get pod -o wide 
NAME                      READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx1-654cb56c4-7t69j    1/1     Running   0          87m   10.244.1.110   node01   <none>           <none>
nginx1-654cb56c4-d8q56    1/1     Running   0          87m   10.244.1.109   node01   <none>           <none>
nginx1-654cb56c4-q89zj    1/1     Running   0          87m   10.244.2.152   node02   <none>           <none>
nginx2-6545dc89c4-4gdmz   1/1     Running   0          90s   10.244.1.119   node01   <none>           <none>
nginx2-6545dc89c4-675ch   1/1     Running   0          90s   10.244.2.176   node02   <none>           <none>
nginx2-6545dc89c4-8kz6b   1/1     Running   0          90s   10.244.2.184   node02   <none>           <none>
nginx2-6545dc89c4-b66r6   1/1     Running   0          90s   10.244.2.183   node02   <none>           <none>
nginx2-6545dc89c4-fc8bj   1/1     Running   0          90s   10.244.2.178   node02   <none>           <none>
nginx2-6545dc89c4-fp6nf   1/1     Running   0          90s   10.244.2.177   node02   <none>           <none>
nginx2-6545dc89c4-klxfc   1/1     Running   0          90s   10.244.2.180   node02   <none>           <none>
nginx2-6545dc89c4-llp4c   1/1     Running   0          90s   10.244.2.182   node02   <none>           <none>
nginx2-6545dc89c4-lw8l5   1/1     Running   0          90s   10.244.2.181   node02   <none>           <none>
nginx2-6545dc89c4-nrtwx   1/1     Running   0          90s   10.244.2.185   node02   <none>           <none>
nginx2-6545dc89c4-ssqrn   1/1     Running   0          90s   10.244.1.118   node01   <none>           <none>
nginx2-6545dc89c4-w49lx   1/1     Running   0          90s   10.244.2.179   node02   <none>           <none>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/52012.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【生日视频制作】黑板写文字美女跳舞2版AE模板修改文字软件生成器教程特效素材【AE模板】

生日视频制作教程黑板写文字美女跳舞2版AE模板修改文字特效广软件告生成神器素材祝福玩法AE模板替换工程 怎么如何做的【生日视频制作】黑板写文字美女跳舞2版AE模板修改文字软件生成器教程特效素材【AE模板】 生日视频制作步骤&#xff1a; 安装AE软件 下载AE模板 把AE模板导…

10、Django Admin修改标题

admin from django.contrib import admin from .models import Category, Origin, Hero, Villain # 添加以下代码 admin.site.site_header "系统管理" admin.site.site_title "管理员界面" admin.site.index_title "欢迎来到这里&#xff…

网络模型及协议介绍

一.OSI七层模型 OSI Open System Interconnect 开放系统互连模型 以前不同厂家所生产的网络设备的标准是不同的&#xff0c;所以为了统一生产规范就制定了OSI这个生产模型。 作用&#xff1a;降低网络进行数据通信复杂度 这个模型的作用第一降低数据通信的复杂度&#xff…

QT cmake vscode 构建流程

采用基于QT creater方式实现&#xff1a; 1. Qt Creator——创建项目——Qt Widgets Application——CMake——Desktop Qt 6.8.0 MSVC2022 64bit——接下来全默认 关键点是选择CMake和构建套件这里用windows的MSVC。 2. 用vscode打开&#xff0c;即可。 可以配置一个调试任务…

JAKA学习2:博途组态配置PROFINET和MODBUS

目录 一、GSD文件安装与设备组态1.1、GSD安装1.2、PROFINET设备组态二、远程启动顺序2.1、启动步骤2.2、安全点配置三、JAKA配置3.1、输入输出点配置一、GSD文件安装与设备组态 1.1、GSD安装 1.2、PROFINET设备组态 二、远程启动顺序 2.1、启动步骤 1、 要保证DO9已开机状态…

驾驭Python与MySQL的桥梁:pymysql的神秘面纱

文章目录 **驾驭Python与MySQL的桥梁&#xff1a;pymysql的神秘面纱**背景&#xff1a;为何选择pymysql&#xff1f;库的简介安装指南简单的库函数使用方法场景应用常见问题与解决方案总结 驾驭Python与MySQL的桥梁&#xff1a;pymysql的神秘面纱 背景&#xff1a;为何选择pym…

java重点学习-redis

一.redis 穿透无中生有key&#xff0c;布隆过滤nul隔离 锁与非期解难题。缓存击穿过期key&#xff0c; 雪崩大量过期key&#xff0c;过期时间要随机。 面试必考三兄弟&#xff0c;可用限流来保底。 1.1 Redis的使用场景 根据自己简历上的业务进行回答 缓存穿透、击穿、雪崩、双…

实验报告: lookie-lookie 项目测试与分析

目录 一、实验目的 二、实验环境 三、实验步骤 1. 下载与准备项目 1.1 从 GitHub 获取项目 1.2 查看项目文件结构 2. 运行项目 2.1 启动项目 2.2 浏览器设置 3. 项目体验 3.1 功能测试 3.2 运行截图 4. 文件结构分析 4.1 总体结构 4.2 主要文件和目录说明 5. 数…

基于人体关节夹角的人体动作识别算法(代码+数据集)

为此本文提出了一个基于人体关节夹角的人体动作识别算法&#xff0c;主要做了以下工作&#xff1a; &#xff08;1&#xff09;提出了一个可解释性强&#xff0c;耗费算力较少且鲁棒性较高的基于人体关节夹角的人体动作序列的特征抽取方法。 &#xff08;2&#xff09;本文所使…

PCL 移动立方体三维重建——RBF算法【2024最新版】

目录 一、算法原理1、算法概述2、参考文献二、代码实现三、结果展示四、相关链接本文由CSDN点云侠原创,原文链接,首发于:2024年9月1日。如果你不是在点云侠的博客中看到该文章,那么此处便是不要脸的爬虫与GPT。 一、算法原理 1、算法概述 该算法实现的是Reconstruction a…

Java并发线程 共享模型之管程 5

1. 生产者消费者 package cn.itcast.testcopy;import cn.itcast.n2copy.util.Sleeper; import lombok.extern.slf4j.Slf4j;import java.util.LinkedList;/*** ClassName: Test21* Package: cn.itcast.testcopy* Description: 生产者消费者** Author: 1043* Create: 2024/9/4 - …

软件测试之压力测试知识总结

&#x1f345; 点击文末小卡片&#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 压力测试 压力测试是一种软件测试&#xff0c;用于验证软件应用程序的稳定性和可靠性。压力测试的目标是在极其沉重的负载条件下测量软件的健壮性和错误处理能力&…

LNMP环境搭建(Linux+nginx+Mysql+PHP)超详细攻略

目录 一.LNMP简介 1.1LNMP架构的特点 二.详细安装步骤 2.1MySQL安装 2.1-1Yum安装 2.1-2 编译安装 2.1-3二进制安装 2.1-4 RPM安装 2.2Nginx安装 2.2-1编译安装nginx 2.2-2yum安装nginx 2.3验证Nginx安装 2.4PHP安装 2.4-1编译安装PHP 2.4-2yum安装PHP 2.5 Nginx 配…

PMP–一、二、三模、冲刺、必刷–分类–14.敏捷–技巧--累积流图

文章目录 技巧一模二模三模14.敏捷–敏捷团队的衡量结果–累积流图&#xff1a;1、 敏捷项目的项目经理担心团队在最近的迭代中失去了动力。项目经理应该使用哪两种工具来分析团队绩效&#xff1f;&#xff08;选择两个&#xff09; 冲刺必刷7.成本管理--挣值分析燃尽图仅能了解…

From Man vs Machine to Man + Machine

From Man vs. Machine to Man Machine: The Art and AI of Stock Analyses 论文阅读 文章目录 From Man vs. Machine to Man Machine: The Art and AI of Stock Analyses 论文阅读 AbstractConstruction and Performance of the AI AnalystMethodologyThe Performance of Ana…

一款用于分析java socket连接问题的工具

network-tools 介绍 network-tools基于sun jdk、Oracle jdk开发&#xff0c;拦截基于java socket请求&#xff0c;它包括 ​ http 客户端 ​ jdbc 客户端 ​ mq 客户端 ​ redis 客户端 目前提供如下功能&#xff1a; ​ 最近端点连接情况 ​ 最近与远程端点连接情况&am…

计算机网络 第1章 概述

文章目录 计算机网络概念计算机网络的组成计算机网络的功能三种数据交换技术电路交换&#xff08;Circuit Switching&#xff09;报文交换&#xff08;message&#xff09;分组交换 三种交换方式性能对比计算机网络的分类计算机网络的性能指标性能指标1&#xff1a;速率性能指标…

【优化】Nginx 配置页面请求不走缓存 浏览器页面禁用缓存

【优化】Nginx 配置页面请求不走缓存 禁用缓存 目录 【优化】Nginx 配置页面请求不走缓存 禁用缓存 对所有请求禁用缓存 对特定location禁用缓存 注意事项 全局禁用缓存 要配置Nginx使其不缓存内容&#xff0c;通常是指禁止浏览器缓存响应的内容&#xff0c;或者是在代理…

单片机-串口通信(二)

目录 一、串口概念 1.相关概念&#xff1a; 按数据传输方式分类&#xff1a; 按时钟分类 二、STM32F103ZET6中串口 USART特性&#xff1a; NRZ数据格式&#xff1a; 三、配置串口通信 查看硬件原理图 软件配置流程 USART相关的寄存器 新建my_usart1.c和my_usart1.h …