kubernetes集群编排——etcd

备份

从镜像中拷贝etcdctl二进制命令

复制代码
[root@k8s1 ~]# docker run -it --rm reg.westos.org/k8s/etcd:3.5.6-0 sh

输入ctrl+pq快捷键,把容器打入后台

获取容器id

复制代码
[root@k8s1 ~]# docker ps

从容器拷贝命令到本机

复制代码
docker container cp c7e28b381f07:/usr/local/bin/etcdctl /usr/local/bin

[root@k8s1 ~]# which etcdctl

删除容器

复制代码
[root@k8s1 ~]# docker rm -f c7e28b381f07

备份

复制代码
[root@k8s1 ~]# ETCDCTL_API=3 etcdctl --endpoints 192.168.92.12:2379 --cert=/root/etcd/server.crt --key=/root/etcd/server.key --cacert=/root/etcd/ca.crt  snapshot save /root/etcd/snapshotdb

查看快照状态

复制代码
[root@k8s1 ~]# ETCDCTL_API=3 etcdctl --endpoints 192.168.92.12:2379 --cert=/root/etcd/server.crt --key=/root/etcd/server.key --cacert=/root/etcd/ca.crt --write-out=table snapshot status /root/etcd/snapshotdb

删除集群资源

复制代码
[root@k8s2 helm]# helm uninstall myapp

[root@k8s2 helm]# kubectl get pod

恢复

停止所有核心组件

复制代码
[root@k8s2 pki]# cd /etc/kubernetes/manifests/

[root@k8s2 manifests]# ls

[root@k8s2 manifests]# mv * /mnt/

移除yaml文件后对应容器自动停止

复制代码
[root@k8s2 manifests]# crictl ps

从快照恢复

复制代码
[root@k8s2 manifests]# cd /var/lib/etcd/

[root@k8s2 etcd]# ls

[root@k8s2 etcd]# mv  member/ /tmp/
复制代码
[root@k8s2 etcd]# ETCDCTL_API=3 etcdctl snapshot restore --data-dir /var/lib/etcd/ /tmp/snapshotdb


[root@k8s2 etcd]# ls

重启所有组件

复制代码
[root@k8s2 etcd]# cd /etc/kubernetes/manifests/

[root@k8s2 manifests]# mv /mnt/* .

yaml文件移动回来后容器自动启动

复制代码
[root@k8s2 manifests]# crictl ps

所有集群节点重启kubelet服务

复制代码
[root@k8s2 manifests]# reboot

[root@k8s3 ~]# reboot

[root@k8s4 ~]# reboot

看到pod恢复表示成功

复制代码
[root@k8s2 ~]# kubectl get pod
相关推荐
可观测性用观测云1 天前
云原生网关 Ingress-Nginx 链路追踪实战:OpenTelemetry 采集与观测云集成方案
nginx·kubernetes
蝎子莱莱爱打怪3 天前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
蝎子莱莱爱打怪6 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀6 天前
Docker部署Nacos
docker·容器
缓解AI焦虑6 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
1candobetter7 天前
Docker Compose Build 与 Up 的区别:什么时候必须重建镜像
docker·容器·eureka
阿里云云原生7 天前
Kubernetes 官方再出公告,强调立即迁移 Ingress NGINX
kubernetes
至此流年莫相忘7 天前
Kubernetes实战篇之配置与存储
云原生·容器·kubernetes
小马爱打代码7 天前
Docker:完全指南从入门到精通
运维·docker·容器