Skip to main content

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:

  1. Back up Kubernetes resources like deployments, configmaps, secrets, etc.

  2. 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.

  1. 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
    ```

  2. 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"
  3. Select the correct kubecontext. Take a backup using the Velero CLI.

    velero backup create test-backup
  4. Check if the backup has completed.

    velero backup describe test-backup
  5. 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 default
  6. Then, attempt to restore from backup.

    velero restore create --include-namespaces default --from-backup test-backup
  7. 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"
info

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

  1. Install the Velero CLI on your machine. For more information and instructions on how to do this, see the Velero docs.

  2. Run one of the following commands to create a new Velero backup.

    Backup options

    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).

    info

    For more information, see the Velero docs.

Restore a backup

  1. Run the following command to list all the available Velero backups that can be restored.

    velero backup get
  2. Run one of the following commands to restore a backup.

    Restore options

    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>

    Note

    Note 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.


Feedback