Velero备份Kubernetes
Velero(前身为Heptio Ark)为您提供了备份和恢复Kubernetes集群资源和持久卷的工具。您可以通过云提供商或内部部署运行Velero。Velero让你:
- 对集群进行备份,并在丢失时进行恢复。
- 迁移集群资源到其他集群。
- 将生产集群复制到开发和测试集群。
Velero包括:
- 在您的集群上运行的服务器
- 本地运行的命令行客户端
1 安装 CLI
|
|
2 安装Minio
|
|
docker启动
|
|
3 启动服务端
在您的本地目录中创建特定于 Velero 的凭证文件
|
|
3.1 启动服务
|
|
3.2 清理
执行以下命令可以删除 velero
|
|
4 备份
为与app=boot
标签选择器匹配的任何对象创建备份
|
|
如果
velero
服务不在默认命名空间,在执行velero
命令时需要添加--namespace <velero-namespaces>
使用app=boot
标签选择器基于 cron 表达式创建定期计划的备份
|
|
列出所有备份
|
|
查看备份描述
|
|
查看备份日志
|
|
基于linux的定时备份
|
|
删除备份
|
|
5 恢复
从 Velero 备份中还原
|
|
恢复到指定命名空间
|
|
列出所有恢复
|
|
查看恢复描述
|
|
查看备份日志
|
|
6 资源过滤
按 namespace、类型或标签筛选对象。
当不使用任何筛选选项时,Velero 会将所有对象包括在备份或还原中。
6.1 Includes
仅包括特定资源,不包括所有其他资源。
如果同时包含通配符和特定资源,则通配符优先。
6.1.1 –include-namespaces
备份 namespace 及其对象。
1
velero backup create <backup-name> --include-namespaces <namespace>
恢复两个 namespace 及其对象。
1
velero restore create <backup-name> --include-namespaces <namespace1>,<namespace2>
6.1.2 –include-resources
备份集群中的所有 deployments:
1
velero backup create <backup-name> --include-resources deployments
恢复集群中的所有 deployments 和 configmaps。
1
velero restore create <backup-name> --include-resources deployments,configmaps
在 namespace 中备份 deployments。
1
velero backup create <backup-name> --include-resources deployments --include-namespaces <namespace>
6.1.3 –include-cluster-resources
此选项可以具有三个可能的值:
true
: 包括所有群集范围的资源。false
: 不包括群集范围的资源。nil
(“auto” 或不提供):- 备份或还原所有 namespace 时,将包括群集范围的资源。 默认值:
true
。 - 使用 namespace 过滤时,不包括群集范围的资源。 默认值:
false
- 除非
--include-cluster-resources = false
,否则如果由自定义操作(例如,PVC-> PV)触发某些相关的群集作用域资源,则可能仍会进行备份 / 还原。
- 除非
- 备份或还原所有 namespace 时,将包括群集范围的资源。 默认值:
备份整个群集,包括群集范围内的资源。
1
velero backup create <backup-name>
仅还原群集中的命名空间资源。
1
velero restore create <backup-name> --include-cluster-resources=false
备份 namespace 并包括群集范围的资源。
1
velero backup create <backup-name> --include-namespaces <namespace> --include-cluster-resources=true
6.1.4 –selector
包括与 label selector 匹配的资源。
|
|
6.2 Excludes
从备份中排除特定资源。
通配符排除将被忽略。
6.2.1 –exclude-namespaces
Exclude
kube-system
from the cluster backup.1
velero backup create <backup-name> --exclude-namespaces kube-system
还原期间排除两个 namespace。
1
velero restore create <backup-name> --exclude-namespaces <namespace1>,<namespace2>
6.2.2 –exclude-resources
从备份中排除 secrets:
1
velero backup create <backup-name> --exclude-resources secrets
排除 secrets 和 rolebindings:
1
velero backup create <backup-name> --exclude-resources secrets,rolebindings
6.2.3 velero.io/exclude-from-backup=true
标签为 velero.io/exclude-from-backup=true
的资源不包括在备份中,即使它包含匹配的选择器标签也是如此。
参考链接: