在CentOS上备份和恢复Kubernetes(k8s)集群的方法有多种,以下是两种常见的方法:
etcd是Kubernetes集群中的关键组件,所有的集群配置、状态和元数据都存储在etcd中。因此,备份etcd数据是备份整个Kubernetes集群的最佳方式。
备份步骤:
etcdctl snapshot save snap1.db
此时在备份文件snap1.db
里是有pod1的信息的。
恢复步骤:
kubectl delete pod pod1
rm -rf /var/lib/etcd/
etcdctl snapshot restore snap1.db --data-dir /var/lib/etcd/
systemctl restart kubelet
kubectl get pods
Velero是一个开源的Kubernetes集群备份、迁移工具,使用对象存储保存集群资源。
安装Velero:
wget https://github.com/vmware-tanzu/velero/releases/download/v1.6.0/velero-v1.6.0-linux-amd64.tar.gz
tar -zxvf velero-v1.6.0-linux-amd64.tar.gz && cd velero-v1.6.0-linux-amd64/
备份:
kubectl create ns velero
apiVersion: v1
kind: PersistentVolume
metadata:
name: velero-pv
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.1.10
path: /velero-backups/k8s-dev
persistentVolumeReclaimPolicy: Retain
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: velero-pv
spec:
storageClassName: ""
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
volumeName: velero-pv
执行创建:
kubectl create -f storage.yaml
velero backup create my-backup --include-namespaces nginx-example --waitBackup request "nginx-backup" submitted successfully.Waiting for backup to complete. You may safely press ctrl-c to stop waiting - your backup will continue in the background..Backup completed with status: Completed. You may check for more information using the commands velero backup describe nginx-backup
恢复:
kubectl apply -f examples/base.yaml
velero restore create my-restore --backup-name my-backup
以上就是在CentOS上备份和恢复Kubernetes集群的两种方法。