nodeSelector(节点选择器)
nodeSelector: 用于将Pod调度到匹配label的Node上,如果没有匹配的标签会调度失败
作用:
- 约束Pod到特定的节点运行
- 完全匹配节点标签
应用场景:
- 专用节点:根据业务将Node分组管理
- 配备特殊硬件:部分Node配有SSD硬盘、GPU
给节点打标签语法格式:
格式:kubectl label nodes <node-name> <label-key>=<label-value>
验证:kubectl get nodes --show-labels
删除:kubectl label nodes <node-name> <label-key>-
举例演示使用nodeSelector
//给node1节点打标签
[root@master manifest]# kubectl label nodes node1.example.com disktype=ssd
//查看标签
[root@master manifest]# kubectl get nodes --show-labels| grep disktype
node1.example.com Ready <none> 22h v1.20.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node1.example.com,kubernetes.io/os=linux
//资源清单文件
[root@master manifest]# cat test.yml
---
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
nodeSelector:
disktype: ssd
containers:
- name: test1
image: busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","sleep 10000"]
//测试
[root@master manifest]# kubectl apply -f test.yml
pod/test created
[root@master manifest]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
test 1/1 Running 0 27s 10.244.1.2 node1.example.com <none> <none>
//删除标签disktype
[root@master manifest]# kubectl label nodes node1.example.com disktype-
[root@master manifest]# kubectl get nodes --show-labels| grep node1
node1.example.com Ready <none> 23h v1.20.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=lin