污点:给节点标记污点,影响节点调度,污点值有三种:一定不会被调度、尽量不会调度、一定不会调度并且驱逐该节点已有的pod到其他节点,可以在资源编排文件上配置污点容忍忽略污点。

# 查看集群节点
[root@k8smaster ~]# kubectl get nodes
NAME        STATUS   ROLES    AGE     VERSION
k8smaster   Ready    master   6h45m   v1.18.0
k8snode1    Ready    <none>   6h43m   v1.18.0
k8snode2    Ready    <none>   6h43m   v1.18.0


# 查看某个节点的污点
[root@k8smaster ~]# kubectl describe node k8smaster | grep Taint
Taints:             node-role.kubernetes.io/master:NoSchedule

# 创建pod
[root@k8smaster ~]# kubectl create deploy web --image=nginx
deployment.apps/web created

# 查看pod的详细信息 
[root@k8smaster ~]# kubectl get pods -o wide
NAME                   READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
web-5dcb957ccc-rbpb7   1/1     Running   0          43s   10.244.2.10   k8snode2   <none>           <none>

# 查看deployment
[root@k8smaster ~]# kubectl get deploy
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
web    1/1     1            1           106s

# 扩展副本
[root@k8smaster ~]# kubectl scale deploy web --replicas=10
deployment.apps/web scaled

# 查看pod详细信息
[root@k8smaster ~]# kubectl get pods -o wide
NAME                   READY   STATUS              RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
web-5dcb957ccc-998xv   1/1     Running             0          49s   10.244.1.7    k8snode1   <none>           <none>
web-5dcb957ccc-dnvcj   1/1     Running             0          49s   10.244.1.8    k8snode1   <none>           <none>
web-5dcb957ccc-fz8h6   1/1     Running             0          64s   10.244.2.20   k8snode2   <none>           <none>
web-5dcb957ccc-jhlvn   1/1     Running             0          49s   10.244.2.22   k8snode2   <none>           <none>
web-5dcb957ccc-jxw97   1/1     Running             0          49s   10.244.2.21   k8snode2   <none>           <none>
web-5dcb957ccc-mvjjq   1/1     Running             0          49s   10.244.2.23   k8snode2   <none>           <none>
web-5dcb957ccc-nk2ft   1/1     Running             0          49s   10.244.1.6    k8snode1   <none>           <none>
web-5dcb957ccc-ns8zb   0/1     ContainerCreating   0          49s   <none>        k8snode1   <none>           <none>
web-5dcb957ccc-v9qhf   0/1     ContainerCreating   0          49s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-wz2w7   0/1     ContainerCreating   0          49s   <none>        k8snode1   <none>           <none>

# 给k8snode1添加污点
[root@k8smaster ~]# kubectl taint node k8snode1 env_role=yes:NoSchedule
node/k8snode1 tainted

# 查看污点
[root@k8smaster ~]# kubectl describe node k8snode1 | grep Taint
Taints:             env_role=yes:NoSchedule

# 删除deploy 
[root@k8smaster ~]# kubectl get deploy
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
web    10/10   10           10          4m7s

[root@k8smaster ~]# kubectl delete deploy web
deployment.apps "web" deleted

# 创建deploy  进行扩容 查看节点调度
[root@k8smaster ~]# kubectl create deploy web --image=nginx
deployment.apps/web created

[root@k8smaster ~]# kubectl scale deploy web --replicas=10
deployment.apps/web scaled

[root@k8smaster ~]# kubectl get pod -o wide
NAME                   READY   STATUS              RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
web-5dcb957ccc-2k6xd   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-5cs8f   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-6z67v   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-79qpz   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-9jwn8   1/1     Running             0          50s   10.244.2.25   k8snode2   <none>           <none>
web-5dcb957ccc-bsk74   1/1     Running             0          25s   10.244.2.26   k8snode2   <none>           <none>
web-5dcb957ccc-k7mnn   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-tpkg4   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-wq2ds   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>
web-5dcb957ccc-z7khb   0/1     ContainerCreating   0          25s   <none>        k8snode2   <none>           <none>

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐