一、根据节点的名字来调度
1)nodeName:用于将pod调度到指定的Node名称上,不会经过默认调度器。
[root@master01 demo3]# kubectl describe nginx-harbor-limit
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Pulling 35s kubelet, node02 Pulling image "42.159.152.148/mydate/nginx:latest"
Normal Pulled 33s kubelet, node02 Successfully pulled image "42.159.152.148/mydate/nginx:latest"
Normal Created 33s kubelet, node02 Created container nginx-harbor-limit
Normal Started 32s kubelet, node02 Started container nginx-harbor-limit
2)nodeSelect:用于将pod调度到匹配Label的Node上,通过默认的调度器来调度。
[root@master01 demo3]# kubectl describe nginx-harbor-limit
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m8s default-scheduler Successfully assigned default/nginx-harbor-limit-757b75774-vg5dz to node01
Normal Pulling 4m6s kubelet, node01 Pulling image "42.159.152.148/mydate/nginx:latest"
Normal Pulled 4m5s kubelet, node01 Successfully pulled image "42.159.152.148/mydate/nginx:latest"
Normal Created 4m5s kubelet, node01 Created container nginx-harbor-limit
Normal Started 4m5s kubelet, node01 Started container nginx-harbor-limit
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-harbor-limit
labels:
app: nginx-harbor-limit
spec:
replicas: 3
selector:
matchLabels:
app: nginx-harbor-limit
template:
metadata:
labels:
app: nginx-harbor-limit
spec:
nodeName: node02 #注意这里是get node看到的名字,不一定是ip地址。
imagePullSecrets:
- name: registry-pull-152.148-harbor
containers:
- name: nginx-harbor-limit
image: 42.159.152.148/mydate/nginx:latest
ports:
- containerPort: 80
二、根据节点标签来调度
[root@master01 demo3]# kubectl label nodes node01 team=A #给节点打标签
[root@master01 demo3]# kubectl label nodes node02 team=B
[root@master01 demo3]# kubectl get nodes --show-labels #标签查看
[root@master01 demo3]# more lable-select.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-harbor-limit
labels:
app: nginx-harbor-limit
spec:
replicas: 3
selector:
matchLabels:
app: nginx-harbor-limit
template:
metadata:
labels:
app: nginx-harbor-limit
spec:
nodeSelector: #根据标签来选择
team: A
imagePullSecrets:
- name: registry-pull-152.148-harbor
containers:
- name: nginx-harbor-limit
image: 42.159.152.148/mydate/nginx:latest
ports:
- containerPort: 80