前置环境:k8s集群
1.创建pod
kubectl create deployment web --image=nginx
查看刚创建的pod分配在哪个节点上
kubectl get pods -o wide
![](https://i-blog.csdnimg.cn/blog_migrate/e0a5ce3d6de47b1b31937c7344807cda.png)
2.然后创建5份pod,我们观察pod分配在哪些node上面
kubectl scale deployment web --replicas=5
![](https://i-blog.csdnimg.cn/blog_migrate/5546f346554092f2d856fdccebc19d9a.png)
3.添加污点
刚才创建的pod 随机分配在compute01、compute11上,如果不想分配在01上,可以通过加污点实现
kubectl taint node compute01 env_role=yes:NoSchedule
NoSchedule属性值表示该node永远不会被调度
![](https://i-blog.csdnimg.cn/blog_migrate/f7ece9b0bb367456ff602cca0be7e42e.png)
我们删除刚创建的五份pod
kubectl delete deployment web
然后重新创建,观察pod分配到哪些节点
kubectl create deployment web --image=nginx
kubectl scale deployment web --replicas=5
![](https://i-blog.csdnimg.cn/blog_migrate/1a7fb85314d6ebe5244ab61db8c3c802.png)
我们发现新创建的pod全部分配到了compute11节点,没有分配在compute01节点,说明我们在compute01上加的污点已经生效了。
4.最后附上删除污点的命令
kubectl taint node compute01 env_role:NoSchedule-
![](https://i-blog.csdnimg.cn/blog_migrate/6bdc79b8e81284ae23dc8e5f441e349b.png)