nodeSelector调度
1.查看节点的label
student@ubuntu:~/schedule$kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
node-193 Ready worker 7d18h v1.12.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node-193,node-role.kubernetes.io/worker=,status=other
ubuntu Ready master 7d19h v1.12.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,key=value,kubernetes.io/hostname=ubuntu,node-role.kubernetes.io/master=,status=vip
2.创建基于nodeselector的pod
student@ubuntu:~/schedule$cat schedule_by_nodeselector.yaml
apiVersion: v1
kind: Pod
metadata:
name: node-selector
spec:
containers:
- name: busybox
image: busybox
command:
- /bin/sleep
- ”10000“
nodeSelector:
kubernetes.io/hostname: ubuntu
student@ubuntu:~/schedule$kubectl create -f schedule_by_nodeselector.yaml
pod/node-selector created
- 查看pod的分布
student@ubuntu:~/schedule$kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
node-selector 1/1 Running 0 2m5s 192.168.0.238 ubuntu <none>
使用taint控制调度
- NoSchedule
student@ubuntu:~/schedule$kubectl taint node ubuntu Taint=true:NoSchedule
node/ubuntu tainted
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
labels:
run: nginx
name: nginx
spec:
replicas: 4
selector:
matchLabels:
run: nginx
template:
metadata:
labels:
run: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
student@ubuntu:~/schedule$kubectl create -f schedule_by_taint.yaml
deployment.extensions/nginx created
student@ubuntu:~/schedule$kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
nginx-dbddb74b8-rvqgs 0/1 ContainerCreating 0 18s <none> node-193 <none>
nginx-dbddb74b8-t7wt6 1/1 Running 0 18s 192.168.1.188 node-193 <none>
nginx-dbddb74b8-v62f9 1/1 Running 0 18s 192.168.1.187 node-193 <none>
nginx-dbddb74b8-w4djm 1/1 Running 0 18s 192.168.1.186 node-193 <none>
2.NoExecute
student@ubuntu:~/schedule$kubectl taint node node-193 Taint=true:NoExecute
student@ubuntu:~/schedule$kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
nginx-dbddb74b8-5nns7 0/1 Pending 0 5s <none> <none> <none>
nginx-dbddb74b8-79nj7 0/1 Pending 0 5s <none> <none> <none>
nginx-dbddb74b8-8kkjt 0/1 Pending 0 5s <none> <none> <none>
nginx-dbddb74b8-pmtm8 0/1 Pending 0 5s <none> <none> <none>
nginx-dbddb74b8-rvqgs 0/1 Terminating 0 100s <none> node-193 <none>
nginx-dbddb74b8-w4djm 0/1 Terminating 0 100s <none> node-193 <none>
3.Tolerations
student@ubuntu:~/schedule$kubectl edit deployments. nginx
tolerations:
- effect: NoExecute
key: Taint
operator: Equal
student@ubuntu:~/schedule$kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
nginx-7df76f4cbc-7xkcv 1/1 Running 0 51s 192.168.1.190 node-193 <none>
nginx-7df76f4cbc-fp5md 1/1 Running 0 41s 192.168.1.193 node-193 <none>
nginx-7df76f4cbc-kgxj6 1/1 Running 0 51s 192.168.1.191 node-193 <none>
nginx-7df76f4cbc-xj8tq 1/1 Running 0 45s 192.168.1.192 node-193 <none>
student@ubuntu:~/schedule$kubectl edit deployments. nginx
tolerations:
- effect: NoSchedule
key: Taint
operator: Equal
value: "true"
student@ubuntu:~/schedule$kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
nginx-567778bb4f-8rgvk 1/1 Running 0 12s 192.168.0.243 ubuntu <none>
nginx-567778bb4f-lcxld 1/1 Running 0 21s 192.168.0.241 ubuntu <none>
nginx-567778bb4f-pvd7g 1/1 Running 0 21s 192.168.0.240 ubuntu <none>
nginx-567778bb4f-t5nkd 1/1 Running 0 16s 192.168.0.242 ubuntu <none>