
深入理解 Velero Backup API 类型velero.io/v1 备份对象的完整字段与源码级解析【免费下载链接】veleroBackup and migrate Kubernetes applications and their persistent volumes项目地址: https://gitcode.com/GitHub_Trending/ve/velero本文以 Velero v1.12 的BackupAPI 类型文档site/content/docs/v1.12/api-types/backup.md为主体完整解析该自定义资源的用途、GroupVersion、全部spec配置字段与status状态字段并结合当前仓库中的类型定义pkg/apis/velero/v1/backup_types.go、控制器默认值填充逻辑pkg/controller/backup_controller.go与服务器配置pkg/cmd/server/config/config.go进行源码级佐证。读完后你将能够独立编写一份完整、可运行的Backup清单准确理解每个过滤字段、超时参数与钩子的语义与默认值并通过status中的阶段与计数字段精确诊断一次备份的执行结果。一、使用方式创建 Backup 即触发备份Backup是 Velero 中用于请求服务器执行一次备份的核心 API 类型。文档明确指出Use theBackupAPI type to request the Velero server to perform a backup. Once created, the Velero Server immediately starts the backup process.也就是说你只需在集群中创建一个kind: Backup对象Velero Server 端的 BackupController 就会立即开始处理它无需额外的触发命令。该类型属于 API Group Versionvelero.io/v1其 Go 结构体定义在 pkg/apis/velero/v1/backup_types.go从源码注释可确认几个关键事实Backup的短名为bakkubebuilder:resource:shortNamebak因此kubectl get bak可以列出所有备份kubectl get bak会自动展示Status、Errors、Warnings、Started、Age等打印列由kubebuilder:printcolumn注解生成Backup是存储版本kubebuilder:storageversion是velero.io/v1组下备份相关的根资源。源码中Backup结构体的注释同样说明了其本质// Backup is a Velero resource that represents the capture of Kubernetes // cluster state at a point in time (API objects and associated volume state). type Backup struct { metav1.TypeMeta json:,inline metav1.ObjectMeta json:metadata,omitempty Spec BackupSpec json:spec,omitempty Status BackupStatus json:status,omitempty }见 pkg/apis/velero/v1/backup_types.go二、完整示例一个注释齐全的 Backup 清单以下是原文档提供的样例对象每个字段都附有语义说明。这是编写生产备份清单时最可靠的参考模板# Standard Kubernetes API Version declaration. Required. apiVersion: velero.io/v1 # Standard Kubernetes Kind declaration. Required. kind: Backup # Standard Kubernetes metadata. Required. metadata: # Backup name. May be any valid Kubernetes object name. Required. name: a # Backup namespace. Must be the namespace of the Velero server. Required. namespace: velero # Parameters about the backup. Required. spec: # CSISnapshotTimeout specifies the time used to wait for # CSI VolumeSnapshot status turns to ReadyToUse during creation, before # returning error as timeout. The default value is 10 minute. csiSnapshotTimeout: 10m # ItemOperationTimeout specifies the time used to wait for # asynchronous BackupItemAction operations # The default value is 1 hour. itemOperationTimeout: 1h # resourcePolicy specifies the referenced resource policies that backup should follow # optional resourcePolicy: kind: configmap name: resource-policy-configmap # Array of namespaces to include in the backup. If unspecified, all namespaces are included. # Optional. includedNamespaces: - * # Array of namespaces to exclude from the backup. Optional. excludedNamespaces: - some-namespace # Array of resources to include in the backup. Resources may be shortcuts (for example po for pods) # or fully-qualified. If unspecified, all resources are included. Optional. includedResources: - * # Array of resources to exclude from the backup. Resources may be shortcuts (for example po for pods) # or fully-qualified. Optional. excludedResources: - storageclasses.storage.k8s.io # Order of the resources to be collected during the backup process. Its a map with key being the plural resource # name, and the value being a list of object names separated by comma. Each resource name has format namespace/objectname. # For cluster resources, simply use objectname. Optional orderedResources: pods: mysql/mysql-cluster-replica-0,mysql/mysql-cluster-replica-1,mysql/mysql-cluster-source-0 persistentvolumes: pvc-87ae0832-18fd-4f40-a2a4-5ed4242680c4,pvc-63be1bb0-90f5-4629-a7db-b8ce61ee29b3 # Whether to include cluster-scoped resources. Valid values are true, false, and # null/unset. If true, all cluster-scoped resources are included (subject to included/excluded # resources and the label selector). If false, no cluster-scoped resources are included. If unset, # all cluster-scoped resources are included if and only if all namespaces are included and there are # no excluded namespaces. Otherwise, if there is at least one namespace specified in either # includedNamespaces or excludedNamespaces, then the only cluster-scoped resources that are backed # up are those associated with namespace-scoped resources included in the backup. For example, if a # PersistentVolumeClaim is included in the backup, its associated PersistentVolume (which is # cluster-scoped) would also be backed up. includeClusterResources: null # Array of cluster-scoped resources to exclude from the backup. Resources may be shortcuts # (for example sc for storageclasses), or fully-qualified. If unspecified, # no additional cluster-scoped resources are excluded. Optional. # Cannot work with include-resources, exclude-resources and include-cluster-resources. excludedClusterScopedResources: {} # Array of cluster-scoped resources to include from the backup. Resources may be shortcuts # (for example sc for storageclasses), or fully-qualified. If unspecified, # no additional cluster-scoped resources are included. Optional. # Cannot work with include-resources, exclude-resources and include-cluster-resources. includedClusterScopedResources: {} # Array of namespace-scoped resources to exclude from the backup. Resources may be shortcuts # (for example cm for configmaps), or fully-qualified. If unspecified, # no namespace-scoped resources are excluded. Optional. # Cannot work with include-resources, exclude-resources and include-cluster-resources. excludedNamespaceScopedResources: {} # Array of namespace-scoped resources to include from the backup. Resources may be shortcuts # (for example cm for configmaps), or fully-qualified. If unspecified, # all namespace-scoped resources are included. Optional. # Cannot work with include-resources, exclude-resources and include-cluster-resources. includedNamespaceScopedResources: {} # Individual objects must match this label selector to be included in the backup. Optional. labelSelector: matchLabels: app: velero component: server # Individual object when matched with any of the label selector specified in the set are to be included in the backup. Optional. # orLabelSelectors as well as labelSelector cannot co-exist, only one of them can be specified in the backup request orLabelSelectors: - matchLabels: app: velero - matchLabels: app: contenteditable="false">【免费下载链接】veleroBackup and migrate Kubernetes applications and their persistent volumes项目地址: https://gitcode.com/GitHub_Trending/ve/velero创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考