gpt4 book ai didi

kubernetes - 删除一个 kubernetes 节点的所有内容

转载 作者:行者123 更新时间:2023-12-03 21:23:27 24 4
gpt4 key购买 nike

如何从 kubernetes 节点中删除所有内容?内容包括部署、副本集等。我试图单独删除部署。但是 kubernetes 会再次重新创建所有 pod。有没有办法删除节点中存在的所有副本集?

最佳答案

如果您正在测试事物,最简单的方法是

kubectl delete deployment --all

虽然如果您使用 minikube,最简单的方法可能是删除机器并使用新节点重新启动
minikube delete
minikube start

如果我们谈论的是生产集群, Kubernetes has a built-in feature to drain a node of the cluster ,从该节点安全地删除所有对象。

You can use kubectl drain to safely evict all of your pods from a node before you perform maintenance on the node. Safe evictions allow the pod’s containers to gracefully terminate and will respect the PodDisruptionBudgets you have specified.

Note: By default kubectl drain will ignore certain system pods on the node that cannot be killed; see the kubectl drain documentation for more details.

When kubectl drain returns successfully, that indicates that all of the pods (except the ones excluded as described in the previous paragraph) have been safely evicted (respecting the desired graceful termination period, and without violating any application-level disruption SLOs). It is then safe to bring down the node by powering down its physical machine or, if running on a cloud platform, deleting its virtual machine.



首先,确定要排空的节点的名称。您可以列出集群中的所有节点
kubectl get nodes

接下来,告诉 Kubernetes 排空节点:
kubectl drain <node name>

一旦它返回(没有给出错误),您可以关闭节点(或者等效地,如果在云平台上,删除支持节点的虚拟机)。 drain等待优雅的终止。在命令完成之前,您不应在机器上操作。

如果在维护操作期间将节点留在集群中,则需要运行
kubectl uncordon <node name>

之后告诉 Kubernetes 它可以继续将新 Pod 调度到节点上。

请注意,如果有任何不受 ReplicationController、ReplicaSet、DaemonSet、StatefulSet 或 Job 管理的 Pod,则 drain除非您使用 --force, as mentioned in the docs 否则不会删除任何 pod .
kubectl drain <node name> --force

关于kubernetes - 删除一个 kubernetes 节点的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48077931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com