Attention: Attention: VolumeSnapshot is a Beta feature enabled by default in Kubernetes 1.17+. Attention: VolumeSnapshot is only available in the driver version "master".
Install Driver with beta snapshot feature as described here
-
Create
StorageClass
If you haven't created a
StorageClass
yet, create one first:kubectl apply -f ./examples/kubernetes/demo-zonal-sc.yaml
-
Create default
VolumeSnapshotClass
kubectl create -f ./examples/kubernetes/snapshot/default-volumesnapshotclass.yaml
-
Create source PVC
kubectl create -f ./examples/kubernetes/snapshot/source-pvc.yaml
-
Generate sample data
Create a sample pod with the source PVC. The source PVC is mounted into
/demo/data
directory of this pod. This pod will create a filesample-file.txt
in/demo/data
directory.kubectl create -f ./examples/kubernetes/snapshot/source-pod.yaml
Check if the file has been created successfully:
kubectl exec source-pod -- ls /demo/data/
The output should be:
lost+found sample-file.txt
-
Create a
VolumeSnapshot
of the source PVCkubectl create -f ./examples/kubernetes/snapshot/snapshot.yaml
-
Verify that
VolumeSnapshot
has been created and it is ready to use:kubectl get volumesnapshot snapshot-source-pvc -o yaml
The output is similar to this:
kind: VolumeSnapshot metadata: creationTimestamp: "2020-05-13T21:48:08Z" finalizers: - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection - snapshot.storage.kubernetes.io/volumesnapshot-bound-protection generation: 1 managedFields: - apiVersion: snapshot.storage.k8s.io/v1beta1 fieldsType: FieldsV1 fieldsV1: f:status: f:readyToUse: {} manager: snapshot-controller operation: Update time: "2020-05-13T21:49:42Z" name: snapshot-source-pvc namespace: default resourceVersion: "531499" selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/snapshot-source-pvc uid: a10fd0ff-b868-4527-abe7-74d5b420731e spec: source: persistentVolumeClaimName: source-pvc volumeSnapshotClassName: csi-gce-pd-snapshot-class status: boundVolumeSnapshotContentName: snapcontent-a10fd0ff-b868-4527-abe7-74d5b420731e creationTime: "2020-05-13T21:48:43Z" readyToUse: true restoreSize: 6Gi
-
Restore the
VolumeSnapshot
into a new PVC:Create a new PVC. Specify
spec.dataSource
section to restore from VolumeSnapshotsnapshot-source-pvc
.kubectl create -f ./examples/kubernetes/snapshot/restored-pvc.yaml
-
Verify sample data has been restored:
Create a sample pod with the restored PVC:
kubectl create -f ./examples/kubernetes/snapshot/restored-pod.yaml
Check data has been restored in
/demo/data
directory:kubectl exec restored-pod -- ls /demo/data/
Verify that the output is:
lost+found sample-file.txt