k8s常用命令
kubernetes 污点操作,PV删除等
·
1 kubernetes 设置 Master 可调度与不可调度
默认情况下,master节点是不参与调度的,且在master节点上有一个污点NoSchedule(表示k8s将不会将Pod调度到具有该污点的Node上),有关污点章节可参考https://www.cnblogs.com/panw/p/16343392.html
语法
kubectl taint node [node] key=value[effect]
[effect] 可取值: [ NoSchedule | PreferNoSchedule | NoExecute ]
NoSchedule: 一定不能被调度
PreferNoSchedule: 尽量不要调度
NoExecute: 不仅不会调度, 还会驱逐Node上已有的Pod
取消污点
取消污点
[root@k8s-master01 ~]# kubectl taint node k8s-master node-role.kubernetes.io/master-
设置污点
# 设置为一定不能被调度
[root@k8s-master01 ~]# kubectl taint node k8s-master01 node-role.kubernetes.io/master="":NoSchedule
node/k8s-master01 tainted
[root@k8s-master01 ~]# kubectl taint node k8s-master02 node-role.kubernetes.io/master="":NoSchedule
node/k8s-master02 tainted
[root@k8s-master01 ~]# kubectl taint node k8s-master03 node-role.kubernetes.io/master="":NoSchedule
node/k8s-master03 tainted
[root@k8s-master01 ~]#
# 查看污点
[root@k8s-master01 ~]# kubectl describe node | grep Ta
Taints: node-role.kubernetes.io/master:NoSchedule
Taints: node-role.kubernetes.io/master:NoSchedule
Taints: node-role.kubernetes.io/master:NoSchedule
Taints: <none>
Taints: <none>
Taints: <none>
Taints: <none>
Taints: <none>
[root@k8s-master01 ~]#
查看验证
# 查看已经调度到maser上的pod没有被驱逐
[root@k8s-master01 ~]# kubectl get pod -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
default hostname-test-cby-58d85dccdb-7zgjj 1/1 Running 1 (2d1h ago) 19d 172.25.244.195 k8s-master01 <none> <none>
default hostname-test-cby-58d85dccdb-8t7zv 1/1 Running 1 (2d1h ago) 19d 172.25.244.196 k8s-master01 <none> <none>
default hostname-test-cby-58d85dccdb-9bqsq 1/1 Running 1 (2d1h ago) 19d 172.25.92.74 k8s-master02 <none> <none>
default hostname-test-cby-58d85dccdb-jj2ml 1/1 Running 1 (2d1h ago) 19d 172.17.125.3 k8s-node01 <none> <none>
default hostname-test-cby-58d85dccdb-k96zl 1/1 Running 1 (2d1h ago) 19d 172.18.195.3 k8s-master03 <none> <none>
default hostname-test-cby-58d85dccdb-lng8b 1/1 Running 1 (2d1h ago) 19d 172.29.115.131 k8s-node04 <none> <none>
default hostname-test-cby-58d85dccdb-lsrbg 1/1 Running 1 (2d1h ago) 19d 172.25.214.195 k8s-node03 <none> <none>
default hostname-test-cby-58d85dccdb-mlv24 1/1 Running 1 (2d1h ago) 19d 172.17.54.131 k8s-node05 <none> <none>
default hostname-test-cby-58d85dccdb-p5vc8 1/1 Running 1 (2d1h ago) 19d 172.27.14.195 k8s-node02 <none> <none>
default hostname-test-cby-58d85dccdb-z6ptf 1/1 Running 1 (2d1h ago) 19d 172.25.214.196 k8s-node03
<none> <none>
[root@k8s-master01 ~]#
设置污点
# 设置为不仅不会调度, 还会驱逐Node上已有的Pod
[root@k8s-master01 ~]# kubectl taint node k8s-master03 node-role.kubernetes.io/master="":NoExecute
node/k8s-master03 tainted
[root@k8s-master01 ~]# kubectl taint node k8s-master02 node-role.kubernetes.io/master="":NoExecute
node/k8s-master02 tainted
[root@k8s-master01 ~]# kubectl taint node k8s-master01 node-role.kubernetes.io/master="":NoExecute
node/k8s-master01 tainted
# 查看污点
[root@k8s-master01 ~]# kubectl describe node | grep Ta
Taints: node-role.kubernetes.io/master:NoExecute
Taints: node-role.kubernetes.io/master:NoExecute
Taints: node-role.kubernetes.io/master:NoExecute
Taints: <none>
Taints: <none>
Taints: <none>
Taints: <none>
Taints: <none>
[root@k8s-master01 ~]#
查看验证
# 查看已经调度到master节点的pod已进行驱逐
[root@k8s-master01 ~]# kubectl get pod -A -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
default mysql-0 2/2 Running 0 34m 172.27.14.206 k8s-node02 <none> <none>
default mysql-1 2/2 Running 0 34m 172.17.125.11 k8s-node01 <none> <none>
default mysql-2 2/2 Terminating 0 34m 172.18.195.10 k8s-master03 <none> <none>
[root@k8s-master01 ~]#
2 k8s删除PV操作
使用以下命令查看pv
kubectl get pv
使用以下命令删除PV,并且在 kubectl delete pv 之后,pv 一直处在 Terminating 状态,使用如下命令也是好使的。
kubectl patch pv {PVC_NAME} -p '{"metadata":{"finalizers":null}}'
使用以下两个命令删除 PV
kubectl delete pv {PVC_NAME}
K8S PV一直Released状态的解决办法
参考: https://blog.csdn.net/wz_cmyc/article/details/120542934
更多推荐
已为社区贡献5条内容
所有评论(0)