Velero is an open-source backup tool that runs in your cluster. It saves a namespace’s Kubernetes resources, and the data on its volumes, to an S3-compatible bucket, and restores them into the cluster later. These steps use an E2E Object Storage bucket, and were tested end to end on a cluster in Delhi.
Before you begin
Section titled “Before you begin”- kubectl is connected to the cluster. See Connect to a cluster with kubectl.
- Helm is installed on your computer, and uses the same kubeconfig.
- You have an E2E Object Storage bucket, and an access key attached to it with a role that can read and write, such as Bucket Writer. Keep the key’s access key and secret key at hand. See Create a bucket and Generate an access key.
- The data you want to back up is on claims made through the storage class
csi-rbd-sc. A restore creates new volumes through a storage class, and a volume made on the Persistent Volume tab has none. See Create a volume from a claim.
Give Velero the bucket’s access key
Section titled “Give Velero the bucket’s access key”-
Write the access key to a file named
credentials-velero. Replace<access-key>and<secret-key>with the key’s values:[default]aws_access_key_id = <access-key>aws_secret_access_key = <secret-key> -
Store the file in a secret in the
veleronamespace:kubectl create namespace velerokubectl create secret generic velero-cloud -n velero --from-file=cloud=credentials-velero
Keep the file as safe as a password, and delete it from your computer once the secret exists.
Install Velero
Section titled “Install Velero”-
Write a file named
values.yamlwith these settings. Replace<bucket>with your bucket’s name:initContainers:- name: velero-plugin-for-awsimage: velero/velero-plugin-for-aws:v1.14.4volumeMounts:- mountPath: /targetname: pluginsconfiguration:backupStorageLocation:- name: defaultprovider: awsbucket: <bucket>config:region: us-east-1s3ForcePathStyle: "true"s3Url: https://objectstore.e2enetworks.netvolumeSnapshotLocation: []defaultVolumesToFsBackup: truesnapshotsEnabled: falsedeployNodeAgent: trueThese are the values the test used. E2E Object Storage accepts both path-style and virtual-hosted addressing, and does not check the region a client sends, so the region and path-style settings are working values rather than requirements. For a bucket in Chennai, use the Chennai endpoint,
https://in-south1-objectstore.e2enetworks.net. The last settings back up volumes by copying their files, through Velero’s node agent, instead of taking snapshots. -
Add the Velero chart repository, and install Velero with your values and the secret:
helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-chartshelm install velero vmware-tanzu/velero --namespace velero --create-namespace --version 12.2.0 -f values.yaml --set credentials.existingSecret=velero-cloud -
Check that Velero reaches the bucket:
kubectl get backupstoragelocation -n veleroThe location named
defaultreadsAvailable.
Back up a namespace
Section titled “Back up a namespace”-
Write a file named
backup.yaml. Replace<backup-name>with a name for this backup, and<namespace>with the namespace to back up:apiVersion: velero.io/v1kind: Backupmetadata:name: <backup-name>namespace: velerospec:includedNamespaces:- <namespace>defaultVolumesToFsBackup: true -
Apply it, and check the backup’s phase:
kubectl apply -f backup.yamlkubectl get backup <backup-name> -n velero -o jsonpath='{.status.phase}'The backup reads InProgress, then
Completed.
With the Velero CLI installed, velero backup create <backup-name> --include-namespaces <namespace>
does the same.
Restore a namespace
Section titled “Restore a namespace”-
Write a file named
restore.yaml. Replace<restore-name>with a name for this restore:apiVersion: velero.io/v1kind: Restoremetadata:name: <restore-name>namespace: velerospec:backupName: <backup-name> -
Apply it, and check the restore’s phase:
kubectl apply -f restore.yamlkubectl get restore <restore-name> -n velero -o jsonpath='{.status.phase}'The restore reads
Completed. Its pods come back, and each claim that was backed up comes back as a new volume with the same data. To check, read a file from a restored pod withkubectl exec.
Your namespaces and their volume data now have a copy in your bucket that you can restore. For more
Velero options, such as scheduled backups, see the Velero documentation.
If a restored claim stays Pending, see
A volume claim stays Pending.