Velero 是一款功能强大的开源工具,用于备份、恢复和迁移 Kubernetes 群集和持久卷。它提供了一种保护 Kubernetes 环境免受意外数据丢失或灾难的可靠方法。
在下面的示例中,我们将介绍在 Kubernetes 集群上安装 Velero 并执行备份和还原操作的基本步骤。
【代码清单】
# Install Velero on your local machine
velero install --provider aws --bucket <YOUR-BUCKET-NAME> --secret-file ./credentials-velero --use-restic --backup-location-config region=<YOUR-REGION>
# Create a backup of your Kubernetes cluster
velero backup create my-cluster-backup --include-namespaces default
# Check the status of the backup
velero backup describe my-cluster-backup --details
# Restore the backup
velero restore create --from-backup my-cluster-backup
【执行结果】
The result will display the progress and completion status of the backup and restore operations. For example, you may see output like:Backup request "my-cluster-backup" submitted successfully.
Run `velero backup describe my-cluster-backup` or `velero backup logs my-cluster-backup` for details.
Restore request "restore-1" submitted successfully.
Run `velero restore describe restore-1` or `velero restore logs restore-1` for details.
Velero 支持多个云提供商,如 AWS、Google Cloud 和 Azure。选项--provider指定了要使用的云提供商。你需要事先配置特定云的凭据,通常是创建一个凭据文件。--use-restic标志是可选的,但如果你想备份持久卷,建议使用该标志。Restic 是 Velero 用于卷备份的开源备份工具。提交备份请求后,Velero 会对指定的命名空间或资源进行快照。快照存储在安装时指定的云存储桶中。您可以使用 velero backup describe 和 velero restore describe 监控备份和还原过程。还原备份会将集群中指定资源的当前状态替换为备份中的状态,因此是灾难恢复的重要工具。
【小知识】
Velero 在更名之前原名为 “Heptio Ark”。它是由 Kubernetes 联合创建者 Joe Beda 和 Craig McLuckie 创立的 Heptio 公司创建的,该公司后来被 VMware 收购。Velero 现在由 VMware 维护,是 Kubernetes 环境中使用最广泛的备份工具之一。