Shared content for Kubernetes snapshots - restore PVC from snap
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.
note
- 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.
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