企业网站建设联系,wordpress图片弹窗,注册咨询公司,佛山国内快速建站kubernetes调度——污点Taint和容忍Toleration 一、通过节点属性调度1、节点名称2、节点标签2.1 查看节点标签2.2 添加标签2.3 修改标签2.4 删除标签2.5 通过节点标签进行调度 二、污点Taint和容忍Toleration1、污点Taint1.1 查看Master节点的污点1.2 添加污点1.3 删除污点 2、… kubernetes调度——污点Taint和容忍Toleration 一、通过节点属性调度1、节点名称2、节点标签2.1 查看节点标签2.2 添加标签2.3 修改标签2.4 删除标签2.5 通过节点标签进行调度 二、污点Taint和容忍Toleration1、污点Taint1.1 查看Master节点的污点1.2 添加污点1.3 删除污点 2、容忍Toleration 一、通过节点属性调度
1、节点名称
[rootk8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master.linux.com Ready control-plane 127d v1.29.1
k8s-node01.linux.com Ready none 127d v1.29.1
k8s-node02.linux.com Ready none 127d v1.29.1apiVersion: apps/v1
kind: Deployment
metadata:name: test1
spec:replicas: 2selector:matchLabels:app: test1template:metadata:labels:app: test1spec:nodeName: k8s-node02.linux.com // 指定工作节点名称containers:- name: test1image: centos:7imagePullPolicy: IfNotPresentcommand:- sleep- 3600[rootk8s-master schedulerTest]# kubectl create -f test1.yaml
deployment.apps/test1 created
[rootk8s-master schedulerTest]#
[rootk8s-master schedulerTest]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
test1-d69854cd5-jgpvm 1/1 Running 0 7s 10.88.242.139 k8s-node02.linux.com none none
test1-d69854cd5-tzx6l 1/1 Running 0 7s 10.88.242.138 k8s-node02.linux.com none none2、节点标签
2.1 查看节点标签
[rootk8s-master schedulerTest]# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master.linux.com Ready control-plane 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-master.linux.com,kubernetes.io/oslinux,node-role.kubernetes.io/control-plane,node.kubernetes.io/exclude-from-external-load-balancers
k8s-node01.linux.com Ready none 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-node01.linux.com,kubernetes.io/oslinux
k8s-node02.linux.com Ready none 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-node02.linux.com,kubernetes.io/oslinux2.2 添加标签
[rootk8s-master schedulerTest]# kubectl label node k8s-node01.linux.com diskssd
node/k8s-node01.linux.com labeled[rootk8s-master schedulerTest]# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master.linux.com Ready control-plane 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-master.linux.com,kubernetes.io/oslinux,node-role.kubernetes.io/control-plane,node.kubernetes.io/exclude-from-external-load-balancers
k8s-node01.linux.com Ready none 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,diskssd,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-node01.linux.com,kubernetes.io/oslinux
k8s-node02.linux.com Ready none 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-node02.linux.com,kubernetes.io/oslinux2.3 修改标签
[rootk8s-master schedulerTest]# kubectl label node k8s-node01.linux.com diskfull --overwrite
node/k8s-node01.linux.com labeled[rootk8s-master schedulerTest]# kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master.linux.com Ready control-plane 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-master.linux.com,kubernetes.io/oslinux,node-role.kubernetes.io/control-plane,node.kubernetes.io/exclude-from-external-load-balancers
k8s-node01.linux.com Ready none 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,diskfull,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-node01.linux.com,kubernetes.io/oslinux
k8s-node02.linux.com Ready none 127d v1.29.1 beta.kubernetes.io/archamd64,beta.kubernetes.io/oslinux,kubernetes.io/archamd64,kubernetes.io/hostnamek8s-node02.linux.com,kubernetes.io/oslinux
[rootk8s-master schedulerTest]# 2.4 删除标签
[rootk8s-master schedulerTest]# kubectl label node k8s-node01.linux.com disk-
node/k8s-node01.linux.com unlabeled2.5 通过节点标签进行调度
apiVersion: apps/v1
kind: Deployment
metadata:name: test2
spec:replicas: 2selector:matchLabels:app: test2template:metadata:labels:app: test2spec:nodeSelector: // 节点标签 ram: highercontainers:- name: test2image: centos:7imagePullPolicy: IfNotPresentcommand:- sleep- 3600二、污点Taint和容忍Toleration
污点、容忍配合使用避免pod被分配不合适的机器
1、污点Taint
污点本质上就是个key-value
1.1 查看Master节点的污点
[rootk8s-master schedulerTest]# kubectl describe node k8s-master.linux.com | grep -i taint
Taints: node-role.kubernetes.io/control-plane:NoSchedule1.2 添加污点
格式# kubectl taint node 节点名称 keyvalue:{NoSchedule|NoExecute|PreferNoSchedule}污点策略: NoSchedule 新建的POD不会再向该节点调度 已经运行在该节点的POD不会受影响 NoExecute 新建的POD不会再向该节点调度 已经运行在该节点的POD同时也会被驱逐 PreferNoSchedule 尽量不向该节点调度新建的POD
[rootk8s-master schedulerTest]# kubectl taint node k8s-node02.linux.com fanerror:NoExecute
node/k8s-node02.linux.com tainted[rootk8s-master schedulerTest]# kubectl describe node k8s-node02.linux.com | grep -i taint
Taints: fanerror:NoExecute1.3 删除污点
格式# kubectl taint node 节点名称 key:{NoSchedule|NoExecute|PreferNoSchedule}-2、容忍Toleration
apiVersion: apps/v1
kind: Deployment
metadata:name: test5
spec:replicas: 2selector:matchLabels:app: test5template:metadata:labels:app: test5spec:containers:- name: test5image: centos:7imagePullPolicy: IfNotPresentcommand:- sleep- 3600tolerations: // 容忍fanerror这个污点- key: fanoperator: Equalvalue: erroreffect: NoExecute[rootk8s-master ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
test5-7575ffc867-hs9hf 1/1 Running 0 2m1s 10.88.242.129 k8s-node02.linux.com none none
test5-7575ffc867-lp4k2 1/1 Running 0 2m1s 10.88.201.193 k8s-node01.linux.com none none