# 集群清理

如果你在集群中使用了一次性服务器进行测试，则可以关闭这些服务器，而无需进一步清理。 你可以使用 **kubectl config delete-cluster** 删除对集群的本地引用。

```properties
kubectl config delete-cluster <cluster_name>
```

但是，如果要更干净地取消配置集群， 则应首先清空节点并确保该节点为空， 然后取消配置该节点。

> kubectl config delete-cluster 命令中的 \<cluster\_name> 是初始化集群时使用的 kubeconfig 文件中配置的集群的名称：
>
> ```yaml
> apiVersion: v1
> clusters:
> - cluster:
>     certificate-authority-data: <base64-encoded-ca-cert>
>     server: https://<cluster-api-server>
>   name: <cluster-name>
> ```

### ~~删除节点~~ <a href="#remove-the-node" id="remove-the-node"></a>

使用适当的凭证与控制平面节点通信，运行：

```bash
kubectl drain <node name> --delete-emptydir-data --force --ignore-daemonsets
```

在删除节点之前，请**重置 kubeadm** **安装的状态**：

```bash
kubeadm reset
```

重置过程不会重置或清除 **iptables** 规则或 **IPVS** 表。如果你希望重置 iptables，则必须手动进行：

```bash
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
```

如果要**重置 IPVS 表**，则必须运行以下命令：

```bash
ipvsadm -C
```

现在删除节点：

```bash
kubectl delete node <节点名称>
```

如果你想重新开始，只需运行 `kubeadm init` 或 `kubeadm join` 并加上适当的参数。

### 清理控制平面 <a href="#clean-up-the-control-plane" id="clean-up-the-control-plane"></a>

你可以在控制平面主机上使用 <mark style="color:blue;">**kubeadm reset**</mark> 来触发尽力而为的清理。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/devops/kubernetes/ji-chu-zhi-shi/an-zhuang/ji-qun/ji-qun-qing-li.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
