VK Cloud logo
Updated atMarch 20, 2024   06:18 AM

Backup with Velero

With Velero you can back up and restore cluster data.

Preparatory steps

  1. Create a cluster Kubernetes of the most current version.

    Place one or more groups of worker nodes in the GZ1 availability area.

    The rest of the cluster parameters are at your discretion.

  2. Make sure that you can connect to the cluster with kubectl.

  3. Make sure that Velero is installed and configured.

  4. Install OpenStack CLI if it is not already installed. Make sure you can authorize in the cloud using it.

1. Deploy application

To get familiar with creating a backup and restoring from it, deploy a demo application coffee. A persistent volume will be attached to this application.

  1. Create a manifest file:

  2. Create the necessary Kubernetes resources based on the manifest:

    kubectl apply -f coffee.yaml

    All the Kubernetes resources needed for the application will be placed in a separate namespace example-app.

  3. Make sure that a disk is created for the persistent volume:

    1. Locate the persistent volume created for the application:

      kubectl get pv -n example-app

      In the table displayed, find the ID of the persistent volume for which example-app/coffee-pvc is listed in the CLAIM column:

      1NAME                                       ...   STATUS   CLAIM                    ...
      2...                                        ...   ...      ...                      ...
      3<persistent volume ID>                     ...   Bound    example-app/coffee-pvc   ...
    2. Get the disk ID for the permanent volume created:

      kubectl describe pv <persistent volume ID> -n example-app

      The output of the command will contain the disk ID in the VolumeHandle parameter:

      1...
      2Source:
      3    Type:              CSI (a Container Storage Interface (CSI) volume source)
      4    Driver:            cinder.csi.openstack.org
      5    FSType:            ...
      6    VolumeHandle:      <disk ID>
      7    ...
    3. Get detailed information about the disk with this ID using the OpenStack CLI:

      openstack volume show <disk ID> --fit-width
  4. Wait until the load balancer is assigned a public IP address.

    Check the status of the load balancer periodically:

    kubectl get svc -n example-app

    The EXTERNAL-IP column should show the public IP address assigned to the load balancer.

  5. Make sure that NGINX is responding to requests:

    curl <public IP address assigned to the load balancer>

    The following should be output:

    The coffee pod says Hello World to everyone! This file is located on the dynamically claimed Cinder ReadWriteOnce persistent volume.

2. Create a backup of the application

  1. Create a manual backup of the entire example-app namespace, which contains the resources you need for the application:

    velero backup create coffee-backup --include-namespaces example-app
  2. Load the backup details:

    velero backup describe coffee-backup
  3. Check the logs of the backup operation (if necessary):

    velero backup logs coffee-backup

It's also possible to do automatic scheduled backups. For more information about scheduled backups, see Velero's help:

velero help

3. Restore the application from the backup

  1. Simulate application failure. To do this, delete the example-app namespace, which contains the resources needed for the application to work:

    kubectl delete ns example-app
  2. Perform a restore from the backup that was created earlier:

    velero restore create --from-backup coffee-backup

    The command will restore the data to the same cluster that was backed up. If you need to restore data to a new cluster:

    1. Create cluster.
    2. Install Velero in the cluster.
    3. Run the above command.
  3. Wait until the load balancer is assigned a public IP address.

    Check the status of the load balancer periodically:

    kubectl get svc -n example-app

    The EXTERNAL-IP column should show the public IP address assigned to the load balancer.

  4. Make sure that NGINX is responding to requests:

    curl <public IP address assigned to the load balancer>

    The following should be output:

    The coffee pod says Hello World to everyone! This file is located on the dynamically claimed Cinder ReadWriteOnce persistent volume.

Delete unused resources

  1. If the Kubernetes resources you created are no longer needed, delete them.

    1kubectl delete ns example-app
    2velero backup delete coffee-backup
  2. If you no longer need Velero, delete it:

    velero uninstall
  3. If you don't need the backups anymore, delete them from the bucket that Velero used.

    If necessary, also delete the bucket itself.

  4. A running cluster consumes computing resources. If you no longer need it: