kubernetes:驱逐node上所有pod

背景:
有时候我们要对一个node节点进行维修,升级,需要重启开关机,那怎么才能做到应用不影响呢?
技术:
我们可以使用 命令操作

封锁节点,先让节点变的不可调度

kubectl cordon <node name>

驱逐pod,该操作做完之后就可以进行节点升级等操作

kubectl drain <node name>

官方文档:
https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#drain

子命令

```bash
Options:
      --delete-local-data=false: Continue even if there are pods using emptyDir (local data that will be deleted when
the node is drained).
      --dry-run=false: If true, only print the object that would be sent, without sending it.
      --force=false: Continue even if there are pods not managed by a ReplicationController, ReplicaSet, Job, DaemonSet
or StatefulSet.
      --grace-period=-1: Period of time in seconds given to each pod to terminate gracefully. If negative, the default
value specified in the pod will be used.
      --ignore-daemonsets=false: Ignore DaemonSet-managed pods.
      --pod-selector='': Label selector to filter pods on the node
  -l, --selector='': Selector (label query) to filter on
      --timeout=0s: The length of time to wait before giving up, zero means infinite

Usage:
  kubectl drain NODE [options]


注意:如果执行过程中不需要驱逐 DS容器,使用–ignore-daemonsets=false
执行之后会有error报错 ,请忽略
在这里插入图片描述

解封锁

kubectl uncordon <node name>

之后正常使用

如果想移除某个节点

kubectl  delete  node  <node name>

重新加回的话 重启node节点,或者重启node上的 kubelet ,kube-proxy即可

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值