lable
查看标签
# 查看所有节点的标签
kubectl get nodes --show-labels
# 查看某个节点的标签
kubectl get node s2 --show-labels
设置标签
# 为所有节点设置标签
kubectl label node --all key=value
# 为某个节点设置标签
kubectl label s2 disk=ssd
取消标签
kubectl lable node s2 disk-
schedule(调度)
标签调度
apiVersion: v1
kind: Pod
metadata:
name: web1
labels:
role: myrole
spec:
nodeSelector:
disk: ssd
containers:
- name: web
image: nginx
imagePullPolicy: Always
ports:
- name: web
containerPort: 80
protocol: TCP
算法调度
污点
- cordon
cordon状态的node不可调度
设置节点为cordon状态
kubectl cordon s2
取消节点cordon状态
kubectl uncordon s2
# 将节点s2设置成不可调度
## 设置之前
[root@s1 pods]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
s1 Ready master 3d22h v1.16.4
s2 Ready <none> 3d22h v1.16.4
s3 Ready <none> 3d22h v1.16.4
## 设置
[root@s1 pods]# kubectl cordon s2
node/s2 cordoned
## 设置之后
[root@s1 pods]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
s1 Ready master 3d22h v1.16.4
s2 Ready,SchedulingDisabled <none> 3d22h v1.16.4
s3 Ready <none> 3d22h v1.16.4
## 取消
[root@s1 pods]# kubectl uncordon s2
node/s2 uncordoned
[root@s1 pods]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
s1 Ready master 3d22h v1.16.4
s2 Ready <none> 3d22h v1.16.4
s3 Ready <none> 3d22h v1.16.4
- drain
drain状态的node不可调度,且已经运行的pod也将会被删除
设置节点为drain状态
kubectl drain s2 --ignore-daemonsets
取消节点drain状态
kubectl uncordon s2
# 将节点s2设置成不可调度
## 设置之前
[root@s1 pods]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
s1 Ready master 3d22h v1.16.4
s2 Ready <none> 3d22h v1.16.4
s3 Ready <none> 3d22h v1.16.4
## 设置
[root@s1 pods]# kubectl drain s2 --ignore-daemonsets
node/s2 cordoned
## 设置之后
[root@s1 pods]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
s1 Ready master 3d22h v1.16.4
s2 Ready,SchedulingDisabled <none> 3d22h v1.16.4
s3 Ready <none> 3d22h v1.16.4
## 取消
[root@s1 pods]# kubectl uncordon s2
node/s2 uncordoned
[root@s1 pods]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
s1 Ready master 3d22h v1.16.4
s2 Ready <none> 3d22h v1.16.4
s3 Ready <none> 3d22h v1.16.4
- taint
taint状态的node,只有容忍污点的pod可以调度到此node
设置节点为taint状态
# kubectl taint nodes 节点名 key值:value值:NoSchedule
kubectl taint nodes s2 keyxx=valuexx:NoSchedule
# 没有value值也可以 kubectl taint nodes 节点名 key值=:NoSchedule
kubectl taint nodes s2 keyxx=:NoSchedule
# 对所有节点设置
kubectl taint nodes --all keyxx=:NoSchedule
删除节点taint状态
kubectl taint nodes s2 keyxx-
查看节点是否设置了taint
kubectl describe nodes s2 | grep -E '(Roles|Taints)'
pod的tolerations配合taint使用
# pod的tolerations属性
tolerations:
- key: "key值"
operator: "Equal"
value: "value值"
effect: "值"
operator的值一般是:
- Equal 意思是value需要和taint的value值一样(默认)
- Exists 意思是可以不指定value的值
# Equal
apiVersion: v1
kind: Pod
metadata:
name: web1
labels:
role: myrole
spec:
nodeSelector:
diskxx: ssdxx
tolerations:
- key: "keyxx"
operator: "Equal"
value: "valuexx"
effect: "NoSchedule"
- key: "key121"
operator: "Equal"
value: "value121"
effect: "NoSchedule"
containers:
- name: web
image: nginx
imagePullPolicy: IfNotPresent
ports:
- name: web
containerPort: 80
protocol: TCP
# Exists
apiVersion: v1
kind: Pod
metadata:
name: web1
labels:
role: myrole
spec:
nodeSelector:
diskxx: ssdxx
tolerations:
- key: "keyxx"
operator: "Exists"
effect: "NoSchedule"
containers:
- name: web
image: nginx
imagePullPolicy: IfNotPresent
ports:
- name: web
containerPort: 80
protocol: TCP