KubeSphere 最佳实战:KubeSphere 和 Kubernetes 集群卸载重装完全指南
2024 年云原生运维实战文档 99 篇原创计划 第 053 篇 |KubeSphere 最佳实战「2024」系列 第 025 篇
你好,欢迎来到运维有术。
本文是一篇实战短文,重点指导您成功卸载已有的 KubeSphere 和 Kubernetes 集群,并在原有服务器上完成重新部署。
实战服务器配置(架构1:1复刻小规模生产环境,只是配置略有不同)
| 主机名 | IP | CPU | 内存 | 系统盘 | 数据盘 | 用途 |
|---|---|---|---|---|---|---|
| ksp-control-1 | 192.168.9.161 | 8 | 16 | 40 | 100 | KubeSphere/k8s-control-plane |
| ksp-control-2 | 192.168.9.162 | 8 | 16 | 40 | 100 | KubeSphere/k8s-control-plane |
| ksp-control-3 | 192.168.9.163 | 8 | 16 | 40 | 100 | KubeSphere/k8s-control-plane |
| ksp-storage | 192.168.9.164 | 2 | 4 | 40 | 500 | NFS-Storage |
| 合计 | 4 | 26 | 52 | 160 | 800 |
实战环境涉及软件版本信息
- 操作系统:openEuler 22.03 LTS SP3 x86_64
- KubeSphere:v4.1.2
- Kubernetes:v1.30.6
- KubeKey: v3.1.7
1. 前言
本文适用于以下场景:
- 部署 KubeSphere 和 Kubernetes 集群失败,需要在原有服务器上重新部署
- 已有 KubeSphere 和 Kubernetes 集群,需要卸载后在原有服务器上重新部署
注意: 卸载 KubeSphere 和 Kubernetes 意味着将其从您的机器上移除。该操作不可逆,且不会进行任何备份。请谨慎操作。
说明: 本文介绍的 Kubernetes 卸载方式仅适用于 Kubernetes 通过 KubeKey 安装的场景。如果您的 Kubernetes 不是通过 KubeKey 安装,请参阅 Kubernetes 官方文档卸载 Kubernetes。
KubeSphere v3 和 v4 卸载 KubeSphere 和 Kubernetes 集群方式略有不同,本文分别介绍。
2. KubeSphere v3.x 操作指南
KubeSphere v3.x 如需删除集群并重建,请执行以下相关命令。
2.1 卸载 KubeSphere 和 Kubernetes 集群
- 进入部署集群时使用的 KubeKey 目录
cd /root/kubekey
- 如果是按照快速入门 All-in-One 安装的 KubeSphere
./kk delete cluster
- 如果是使用配置文件安装的 KubeSphere
./kk delete cluster -f config-sample.yaml
说明: config-sample.yaml 是部署集群时的配置文件。
- 卸载成功会提示如下信息
21:56:19 CST Pipeline[DeleteClusterPipeline] execute successfully
2.2 清理未删除干净的信息
这一步是核心,很多部署失败都是因为残留的配置未清理干净。
- 进入部署集群时使用的 KubeKey 目录,查看数据
cd /root/kubekey
$ ls
kk ksp-k8s-v1306.yaml kubekey kubekey-v3.1.7-linux-amd64.tar.gz
- 查看 kubekey 目录的数据
$ ls /root/kubekey/kubekey
cni config-opsxlab containerd crictl etcd helm ksp-control-1 ksp-control-2 ksp-control-3 kube logs pki runc
- 删除 pki 和以节点名命名的所有目录(建议做好备份)
cd /root/kubekey/kubekey
rm -rf ksp-control-1 ksp-control-2 ksp-control-3 pki
3. KubeSphere v4.x 操作指南
KubeSphere v4.x 如需删除集群并重建,请执行以下相关命令。
3.1 卸载 KubeSphere
KubeSphere v4 的部署方式采用了 Helm,所以卸载时需要使用 Helm。
helm -n kubesphere-system uninstall ks-core
3.2 卸载扩展组件
可选操作,上面的操作只是卸载了 KubeSphere Core,如果您安装了扩展组件,还需要手工卸载扩展组件。
- 查看通过 Helm 安装的扩展组件
$ helm list -A
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
ks-core kubesphere-system 1 2024-11-08 09:16:57.860023524 +0800 CST deployed ks-core-1.1.3 v4.1.2
whizard-monitoring kubesphere-monitoring-system 1 2024-11-08 03:10:46.242966821 +0000 UTC deployed whizard-monitoring-1.1.1
whizard-monitoring-agent kubesphere-monitoring-system 1 2024-11-08 03:14:36.072353417 +0000 UTC deployed whizard-monitoring-1.1.1
whizard-telemetry extension-whizard-telemetry 1 2024-11-08 03:01:26.269210475 +0000 UTC deployed whizard-telemetry-1.2.2
- 卸载扩展组件(以监控组件为例,其它组件类似)
helm -n kubesphere-monitoring-system uninstall whizard-monitoring whizard-monitoring-agent
# helm -n extension-whizard-telemetry uninstall whizard-telemetry
3.3 卸载 Kubernetes 集群
- 进入部署集群时使用的 KubeKey 目录
cd /root/kubekey
- 如果是按照快速入门 All-in-One 安装的 Kubernetes
./kk delete cluster
- 如果是使用配置文件安装的 Kubernetes
./kk delete cluster -f config-sample.yaml
说明: config-sample.yaml 是部署集群时的配置文件。
- 卸载成功会提示如下信息
21:56:19 CST Pipeline[DeleteClusterPipeline] execute successfully
3.4 清理未删除干净的信息
这一步是核心,很多部署失败都是因为残留的配置未清理干净。
- 进入部署集群时使用的 KubeKey 目录,查看数据
cd /root/kubekey
$ ls
kk ksp-k8s-v1306.yaml kubekey kubekey-v3.1.7-linux-amd64.tar.gz
- 查看 kubekey 目录的数据
$ ls /root/kubekey/kubekey
cni config-opsxlab containerd crictl etcd helm ksp-control-1 ksp-control-2 ksp-control-3 kube logs pki runc
- 删除 pki 和以节点名命名的所有目录(建议做好备份)
cd /root/kubekey/kubekey
rm -rf ksp-control-1 ksp-control-2 ksp-control-3 pki
4. 重新部署 KubeSphere 和 Kubernetes 集群
参考下面的部署文档,重新部署 KubeSphere 和 Kubernetes 集群。
征服 Docker 镜像访问限制 KubeSphere v3.4.1 成功部署全攻略
33 张高清大图,带你玩转 KubeSphere v4.1.2 部署与扩展组件安装
理论上不会再失败,如有问题可以在评论区留言,或是加我wx 「opsxlab」,邀您入群一起探讨本文的知识点。
以上,就是我今天分享的全部内容。下一期分享的内容还没想好,敬请期待开盲盒。
如果你喜欢本文,请分享、收藏、点赞、评论! 请持续关注 @运维有术,及时收看更多好文!
欢迎加入 「知识星球|运维有术」 ,获取更多的 KubeSphere、Kubernetes、云原生运维、自动化运维、AI 大模型等实战技能。未来运维生涯始终有我坐在你的副驾。
免责声明:
- 笔者水平有限,尽管经过多次验证和检查,尽力确保内容的准确性,但仍可能存在疏漏之处。敬请业界专家大佬不吝指教。
- 本文所述内容仅通过实战环境验证测试,读者可学习、借鉴,但严禁直接用于生产环境。由此引发的任何问题,作者概不负责!
Get 本文实战视频(请注意,文档视频异步发行,请先关注)
版权声明
- 所有内容均属于原创,感谢阅读、收藏,转载请联系授权,未经授权不得转载。