Create and use cloud snapshots in Rancher
This document shows how you can create cloud snapshots of Portworx volumes and how you can clone those snapshots to use them in pods.
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 Portworx 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 create and configure credentials section to setup secrets.
Create cloud snapshots​
With cloud snapshots, you can either snapshot individual PVCs one by one or snapshot a group of PVCs.
Instructions for backing up a PVC with consistency to cloud and restore PVCs. Instructions for backing up a group of PVCs with consistency to cloud and restore PVCs from the backups.📄 Cloud backups for single PVCs
📄 Cloud backups for 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, add the snapshot.alpha.kubernetes.io/snapshot annotation to refer to the snapshot name. If the snapshot exists in another namespace, you should specify the snapshot namespace with the stork.libopenstorage.org/snapshot-source-namespace annotation in the PVC.
The Retain policy is important if you need to keep the volume in place, even after removing the Kubernetes objects from a cluster.
- As shown in the following example, the storageClassName should be the Stork StorageClass
stork-snapshot-sc. - When using this storage class the PVC is creating with
deleteas Retain policy. However, if the source PVC is having the policy asretain, then this will not be inherited to the restored PVC. After the restore, you should manually verify the retain policy and change it if needed.
-
Create a new PVC using the following spec:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: vdbench-restore
namespace: vdbench-sv4-svc-autojournal
annotations:
snapshot.alpha.kubernetes.io/snapshot: vdbench-pvc-output-sv4-svc-schedule-interval-2024-01-10-225924
stork.libopenstorage.org/snapshot-source-namespace: vdbench-sv4-svc-autojournal
spec:
accessModes:
- ReadWriteOnce
storageClassName: stork-snapshot-sc
resources:
requests:
storage: 10Gi -
Once the above PVC specification is applied, verify that Stork has created a PVC that is backed by a clone of the specified Portworx volume snapshot(
vdbench-pvc-output-sv4-svc-schedule-interval-2024-01-10-225924):storkctl -n vdbench-sv4-svc-autojournal get volumesnapshotNAME PVC STATUS CREATED COMPLETED TYPE
vdbench-pvc-output-sv4-svc-schedule-interval-2024-01-10-225924 vdbench-pvc-output-sv4-svc Ready 10 Jan 24 14:59 PST 10 Jan 24 14:59 PST cloud -
Verify that a cloud snapshot is restored to the PVC created above:
kubectl get pvc -n vdbench-sv4-svc-autojournalNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
vdbench-pvc-enc-sv4-svc Bound pvc-xxxxxxxx-xxxx-xxxx-xxxx-a2959220f31b 50Gi RWX vdbench-sc-sv4-svc-auto 29m
vdbench-pvc-output-sv4-svc Bound pvc-xxxxxxxx-xxxx-xxxx-xxxx-ceda98f2ae06 5Gi RWX vdbench-sc-sv4-svc-auto 29m
vdbench-restore Bound pvc-xxxxxxxx-xxxx-xxxx-xxxx-9916a6098418 10Gi RWO stork-snapshot-sc 4m46sIn the above example output, the
vdbench-restorePVC is in aBoundstatus and is associated with the correct volume that represents the restored snapshot.
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.
In-place restore using VolumeSnapshotRestore works only for applications deployed using the stork scheduler.
If you're not using the Stork scheduler, Portworx displays the following error when describing the VolumeSnapshotRestore resource:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning Failed 5s (x2 over 15s) stork application not scheduled by stork scheduler
-
Create a
VolumeSnapshotRestoreYAML 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-snapshotwhich was created in themysql-snap-restore-splocalnamespace to a PVC calledmysql-snap-inrestorein thedefaultnamespace:apiVersion: stork.libopenstorage.org/v1alpha1
kind: VolumeSnapshotRestore
metadata:
name: mysql-snap-inrestore
namespace: default
spec:
sourceName: mysql-snapshot
sourceNamespace: mysql-snap-restore-splocal - apiVersion as
-
Place the spec into a file called
mysql-cloud-snapshot-restore.yamland apply it:kubectl apply -f mysql-cloud-snapshot-restore.yaml -
You can enter the following command to see the status of the restore process:
storkctl get volumesnapshotrestoreNAME SOURCE-SNAPSHOT SOURCE-SNAPSHOT-NAMESPACE STATUS VOLUMES CREATED
mysql-snap-inrestore mysql-snapshot default Successful 1 23 Sep 19 21:55 EDTYou can also use the
kubectl describecommand to retrieve more detailed information about the status of the restore process.Example:
kubectl describe volumesnapshotrestore mysql-snap-inrestoreName: 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: xxxxxxxx-xxxx-xxxx-xxxx-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-xxxxxxxx-xxxx-xxxx-xxxx-320ff611f4ca
Status: Successful
Volume: pvc-xxxxxxxx-xxxx-xxxx-xxxx-000c295d6364
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Successful 0s stork Snapshot in-Place Restore completed