Back Up and Restore Using Velero
Velero is a backup and restore solution that allows to backup Kubernetes cluster resources and restore them later. From H2O AI Hybrid Cloud (HAIC) v23.10.0 onwards, you can back up and restore using Velero on AWS, GCP, Azure, and OpenShift.
A Backup process consists of two tasks:
Back up Kubernetes resources like deployments, configmaps, secrets, etc.
Snapshot persistent volumes (PVs)
Both backing up, and snapshotting are required to recover from disasters. Velero supports both backup and snapshot. Object storage, related resources, and helm release creation are governed by the enable_velero
variable. Velero is enabled by default. If you do not want to create Velero and related resources, set enable_velero=false
.
Prerequisites
- Velero installed on the H2O AI Cloud environment
Validate Velero installation
Generally, it is a good practice to validate that Velero has been installed successfully. Once Velero is installed, the pod should not be in a crash looback state. A crash loopback can occur if the Velero pod cannot reach or authenticate with the configured object storage.
To validate that Velero has been installed correctly on your environment, you can create a pod and a PersistentVolumeClaim (PVC), and store data in the PVC. Then, delete them and restore using Velero. If this process works seamlessly, your Velero installation is a success.
Follow the steps below to test this out.
Apply the following Pod and PVC.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: backup-test-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: backup-test-pod
spec:
volumes:
- name: backup-test-storage
persistentVolumeClaim:
claimName: backup-test-claim
containers:
- name: backup-test-container
image: nginx
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: backup-test-storage
```Run the following command to write “Success“ in to a file on the PersistentVolume(PV).
kubectl exec pod/backup-test-pod -n default -it -- sh -c "echo 'Success' > /usr/share/nginx/html/index.html"
Select the correct kubecontext. Take a backup using the Velero CLI.
velero backup create test-backup
Check if the backup has completed.
velero backup describe test-backup
Once the backup is complete, delete the pod and the PVC.
kubectl delete po/backup-test-pod -n default
kubectl delete pvc/backup-test-claim -n defaultThen, attempt to restore from backup.
velero restore create --include-namespaces default --from-backup test-backup
Run the following command. It should output “Success“.
kubectl exec pod/backup-test-pod -n default -it -- sh -c "cat /usr/share/nginx/html/index.html"
The restored PVs and PVCs should have the following annotations: velero.io/restore-name
, velero.io/backup-name
.
If you were able to execute these steps without a hitch, Velero has been succesfully installed in your environment.
Create a Velero backup
Install the Velero CLI on your machine. For more information and instructions on how to do this, see the Velero docs.
Run one of the following commands to create a new Velero backup.
Backup options- All resources
- Scheduled backup
- A specific namespace
To back up all resources and snapshot all PVs:
velero backup create <backup-name>
Note that this will only work on AWS, GCP, and Azure. It will not work on Openshift(FSB) as you have to explicity annotate PVs).
To back up resources using a schedule:
kubectl get schedule -n velero
velero backup create --from-schedule <schedule-name>To back up a single namespace and it's objects:
velero backup create <backup-name> --include-namespaces <namespace>
infoFor more information, see the Velero docs.
Restore a backup
Run the following command to list all the available Velero backups that can be restored.
velero backup get
Run one of the following commands to restore a backup.
Restore options- All resources
- Selected resources/namespaces
To restore all resources within the backup, choose the backup that you wish to restore from the list retrieved above, and run the following command specifying the chosen backup name. Restoring a backup restores all resources within the backup, including both Kubernetes objects and PVs by default.
velero restore create <restore-name> --from-backup <backup-name>
To restore selected resources from selected namespaces:
velero restore create --from-backup <backup-name> --include-resources <resource-names> --include-namespaces <namespaces>
NoteNote that if a resource already exists, it will be ignored by default. Existing resources will not recreated. To restore a resource to a previous state, we recommended contacting an H2O resource for further assistance.
- Submit and view feedback for this page
- Send feedback about H2O AI Cloud | Docs to cloud-feedback@h2o.ai