Kubernetes实战(十七)-设置kubernetes允许master调度pod

发布时间:2024年01月13日

1 taint节点调度策略

  • NoSchedule: 一定不能被调度
  • PreferNoSchedule: 尽量不要调度
  • NoExecute: 不仅不会调度, 还会驱逐Node上已有的Pod

2 查看节点调度

$ kubectl describe node|grep -E "Name:|Taints:"
Name:               ops-master-1
Taints:             node-role.kubernetes.io/master:NoSchedule
Name:               ops-master-2
Taints:             node-role.kubernetes.io/master:NoSchedule
Name:               ops-master-3
Taints:             node-role.kubernetes.io/master:NoSchedule
Name:               ops-worker-1
Taints:             <none>
Name:               ops-worker-2
Taints:             <none>

3 设置master节点可调度

3.1 允许所有的master节点均可调度pod

$ kubectl taint nodes --all node-role.kubernetes.io/master-
node/ops-master-1 untainted
node/ops-master-2 untainted
node/ops-master-3 untainted
taint "node-role.kubernetes.io/master" not found
taint "node-role.kubernetes.io/master" not found
# 因为worker节点无node-role.kubernetes.io/master-标签,所以执行上述操作会提示节点不存在。

设置完以后,查看发现有pod已经调度在ops-master-3节点上。

$ kubectl get pod -o wide 
NAME                           READY   STATUS    RESTARTS   AGE     IP              NODE           NOMINATED NODE   READINESS GATES
nginx-node1-5f9555db6b-g4cg7   1/1     Running   0          9m20s   172.25.186.67   ops-master-3   <none>           <none>
nginx-node1-5f9555db6b-rq2pn   1/1     Running   0          3h4m    172.25.78.77    ops-worker-1   <none>           <none>
nginx-test-6b7c99bbb-8sfh7     1/1     Running   0          175m    172.25.50.140   ops-worker-2   <none>           <none>
nginx-test-6b7c99bbb-hp62s     1/1     Running   0          175m    172.25.50.139   ops-worker-2   <none>           <none>

3.2 设置master节点不可调度

# 设置ops-master-1不可调度
$ kubectl taint node ops-master-1 node-role.kubernetes.io/master=:NoSchedule
node/ops-master-1 tainted
# 设置ops-master-3不可调度且已有pod被驱逐
$ kubectl taint node ops-master-3 node-role.kubernetes.io/master=:NoExecute
node/ops-master-3 tainted
$ kubectl describe node|grep -E "Name:|Taints:"
Name:               ops-master-1
Taints:             node-role.kubernetes.io/master:NoSchedule
Name:               ops-master-2
Taints:             <none>
Name:               ops-master-3
Taints:             <none>
Name:               ops-worker-1
Taints:             <none>
Name:               ops-worker-2
Taints:             <none>
$ kubectl get pod -o wide 
NAME                           READY   STATUS    RESTARTS   AGE     IP              NODE           NOMINATED NODE   READINESS GATES
nginx-node1-5f9555db6b-89hrf   0/1     Pending   0          58s     <none>          <none>         <none>           <none>
nginx-node1-5f9555db6b-rq2pn   1/1     Running   0          3h10m   172.25.78.77    ops-worker-1   <none>           <none>
nginx-test-6b7c99bbb-8sfh7     1/1     Running   0          3h1m    172.25.50.140   ops-worker-2   <none>           <none>
nginx-test-6b7c99bbb-hp62s     1/1     Running   0          3h1m    172.25.50.139   ops-worker-2   <none>           <none>

?原在ops-master-3节点节点上的pod被驱逐。

一般情况下,master节点均设置不可调度以确保集群高可用性要求。

?

文章来源:https://blog.csdn.net/ygq13572549874/article/details/135572194
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。