Create and use cloud snapshots


This document will show you how to create cloud snapshots of Portworx volumes and how you can clone those snapshots to use them in pods.

NOTE: You cannot use an older version of Portworx to restore a cloud snapshot created with a newer one. For example, if you’re running Portworx 2.1, you can’t restore a cloud snapshot created with Portworx 2.2.

Back up a volume and restore it to the same Portworx cluster

This section shows how you can back up a volume and restore it to the same Portworx cluster.

Prerequisites

  • This requires that you already have Stork installed and running on your Kubernetes cluster. If you fetched the Portworx specs from the Portworx spec generator in PX-Central and used the default options, Stork is already installed.
  • Cloud snapshots using below method is supported in Portworx version 1.4 and above.
  • Cloud snapshots (for aggregated volumes) using below method is supported in Portworx version 2.0 and above.

Configuring cloud secrets

To create cloud snapshots, one needs to setup secrets with Portworx which will get used to connect and authenticate with the configured cloud provider.

Follow instructions on the pxctl credentials page to setup secrets.

Create cloud snapshots

With cloud snapshots, you can either snapshot individual PVCs one by one or snapshot a group of PVCs.

Restore cloud snapshots

Once you’ve created a cloud snapshot, you can restore it to a new PVC or the original PVC.

Restore a cloud snapshot to a new PVC

When you install Stork, it also creates a storage class called stork-snapshot-sc. This storage class can be used to create PVCs from snapshots.

To create a PVC from a snapshot, you would add the snapshot.alpha.kubernetes.io/snapshot annotation to refer to the snapshot name. If the snapshot exists in another namespace, the snapshot namespace should be specified with the stork.libopenstorage.org/snapshot-source-namespace annotation in the PVC.

Note that the storageClassName needs to be the Stork StorageClass stork-snapshot-sc as in the example below.

The following spec restores a PVC from the snapshot in the example above:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-snap-clone
  annotations:
    snapshot.alpha.kubernetes.io/snapshot: mysql-snapshot
spec:
  accessModes:
     - ReadWriteOnce
  storageClassName: stork-snapshot-sc
  resources:
    requests:
      storage: 2Gi

Once you apply the above spec, you will see a PVC created by Stork. This PVC will be backed by a Portworx volume clone of the snapshot created above.

kubectl get pvc
NAMESPACE   NAME                                   STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS                AGE
default     mysql-data                             Bound     pvc-f782bf5c-20e7-11e8-931d-0214683e8447   2Gi        RWO            px-mysql-sc                 2d
default     mysql-snap-clone                       Bound     pvc-05d3ce48-2280-11e8-98cc-0214683e8447   2Gi        RWO            stork-snapshot-sc           2s

Restore a cloud snapshot to the original PVC

When you perform an in-place restore to a PVC, Stork takes the pods using that PVC offline, restores the volume from the snapshot, then brings the pods back online.

  1. Create a VolumeSnapshotRestore YAML file specifying the following:

    • apiVersion as stork.libopenstorage.org/v1alpha1
    • kind as VolumeSnapshotRestore
    • metadata.name with the name of the object that performs the restore
    • metadata.namespace with the name of the target namespace
    • spec.sourceName with the name of the snapshot you want to restore
    • spec.sourceNamespace with the namespace in which the snapshot resides

    The following example restores data from a snapshot called mysql-snapshot which was created in the mysql-snap-restore-splocal namespace to a PVC called mysql-snap-inrestore in the default namespace:

     apiVersion: stork.libopenstorage.org/v1alpha1
     kind: VolumeSnapshotRestore
     metadata:
       name: mysql-snap-inrestore
       namespace: default
     spec:
       sourceName: mysql-snapshot
       sourceNamespace: mysql-snap-restore-splocal
  2. Place the spec into a file called mysql-cloud-snapshot-restore.yaml and apply it:

     kubectl apply -f mysql-cloud-snapshot-restore.yaml
  3. You can enter the following command to see the status of the restore process:

     storkctl get volumesnapshotrestore
     NAME                   SOURCE-SNAPSHOT   SOURCE-SNAPSHOT-NAMESPACE   STATUS          VOLUMES   CREATED
     mysql-snap-inrestore   mysql-snapshot    default                     Successful      1         23 Sep 19 21:55 EDT  

    You can also use the kubectl describe command to retrieve more detailed information about the status of the restore process.

    Example:

      kubectl describe volumesnapshotrestore mysql-snap-inrestore
      Name:         mysql-snap-inrestore
      Namespace:    default
      Labels:       <none>
      Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                      {"apiVersion":"stork.libopenstorage.org/v1alpha1","kind":"VolumeSnapshotRestore","metadata":{"annotations":{},"name":"mysql-snap-inrestore...
      API Version:  stork.libopenstorage.org/v1alpha1
      Kind:         VolumeSnapshotRestore
      Metadata:
        Creation Timestamp:  2019-09-23T17:24:30Z
        Generation:          5
        Resource Version:    904014
        Self Link:           /apis/stork.libopenstorage.org/v1alpha1/namespaces/default/volumesnapshotrestores/mysql-snap-inrestore
        UID:                 00474a5c-de27-11e9-986b-000c295d6364
      Spec:
        Group Snapshot:    false
        Source Name:       mysql-snapshot
        Source Namespace:  default
      Status:
        Status:  Successful
        Volumes:
          Namespace:  default
          Pvc:        mysql-data
          Reason:     Restore is successful
          Snapshot:   k8s-volume-snapshot-cb909cf9-de26-11e9-ad56-320ff611f4ca
          Status:     Successful
          Volume:     pvc-8b996a17-de26-11e9-986b-000c295d6364
      Events:
        Type    Reason      Age   From   Message
        ----    ------      ----  ----   -------
        Normal  Successful  0s    stork  Snapshot in-Place  Restore completed

References



Last edited: Thursday, Apr 16, 2020