如何优雅地从 Kubernetes 中删除节点? [英] How to gracefully remove a node from Kubernetes?

查看:29
本文介绍了如何优雅地从 Kubernetes 中删除节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想增加/减少机器数量以增加/减少 Kubernetes 集群中的节点数量.当我添加一台机器时,我能够成功地向Kubernetes注册它;因此,按预期创建了一个新节点.但是,我不清楚以后如何顺利关闭机器.一个好的工作流程是:

I want to scale up/down the number of machines to increase/decrease the number of nodes in my Kubernetes cluster. When I add one machine, I’m able to successfully register it with Kubernetes; therefore, a new node is created as expected. However, it is not clear to me how to smoothly shut down the machine later. A good workflow would be:

  1. 将与我要关闭的机器相关的节点标记为不可调度;
  2. 在其他节点中启动在该节点中运行的 pod;
  3. 优雅地删除节点中正在运行的 Pod;
  4. 删除节点.

如果我理解正确的话,即使 kubectl drain (讨论) 不符合我的预期,因为它在删除 Pod 之前没有启动它们(它依赖复制控制器在之后启动 Pod,这可能会导致停机).我错过了什么吗?

If I understood correctly, even kubectl drain (discussion) doesn't do what I expect since it doesn’t start the pods before deleting them (it relies on a replication controller to start the pods afterwards which may cause downtime). Am I missing something?

我应该如何正确关闭机器?

How should I properly shutdown a machine?

推荐答案

列出节点并获取你想排空或(从集群中移除)

List the nodes and get the <node-name> you want to drain or (remove from cluster)

kubectl get nodes

1) 先排空节点

kubectl drain <node-name>

您可能不得不忽略机器中的守护进程集和本地数据

You might have to ignore daemonsets and local-data in the machine

kubectl drain <node-name> --ignore-daemonsets --delete-local-data

2) 编辑节点的实例组(仅当您使用 kops 时)

2) Edit instance group for nodes (Only if you are using kops)

kops edit ig nodes

将 MIN 和 MAX 大小设置为 -1只需保存文件(无需额外操作)

Set the MIN and MAX size to whatever it is -1 Just save the file (nothing extra to be done)

您仍然可能会在已耗尽的节点中看到一些与守护进程相关的 pod,例如网络插件、用于日志的 fluentd、kubedns/coredns 等

You still might see some pods in the drained node that are related to daemonsets like networking plugin, fluentd for logs, kubedns/coredns etc

3) 最后删除节点

kubectl delete node <node-name>

4) 在 s3 中为 KOPS 提交状态:(仅当您使用 kops 时)

4) Commit the state for KOPS in s3: (Only if you are using kops)

kops update cluster --yes

或(如果您使用的是 kubeadm)

OR (if you are using kubeadm)

如果您正在使用 kubeadm 并希望将机器重置为运行 kubeadm join 之前的状态,然后运行

If you are using kubeadm and would like to reset the machine to a state which was there before running kubeadm join then run

kubeadm reset

这篇关于如何优雅地从 Kubernetes 中删除节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆