Volume Snapshot and Clones Provisioning Examples

This example is more complex and is composed of six different stages:

  • Stage 1: Create VolumeSnapshotClass.

  • Stage 2: Create Example PVC and POD.

  • Stage 3: Take a Snapshot from the PVC created in Stage #2.

  • Stage 4: Create a PVC from the Snapshot created in Stage #3 and create a POD that uses it.

  • Stage 5: Create a PVC from the PVC created in Stage #4 and create a POD that uses it.

  • Stage 6: Uninstall Snapshot Workloads.

The examples are dependent on one another, so you must run them in order.

Stage 1: Create VolumeSnapshotClass

Create a VolumeSnapshotClass:

kubectl create -f examples/snaps-example-snapshot-class.yaml

Stage 2: Create Example PVC and POD

Running the following command:

kubectl create -f examples/snaps-example-pvc-workload.yaml
persistentvolumeclaim/example-pvc created
pod/example-pod created

Verify that PV, PVC are created and in Bounded state and POD is in Running state.

kubectl get pv,pvc,pods
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO Delete Bound default/example-pvc example-sc 57s

NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/example-pvc Bound pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO example-sc 58s

NAME READY STATUS RESTARTS AGE
pod/example-pod 1/1 Running 0 58s

Stage 3: Take a Snapshot from the PVC created in Stage #2

Create a snapshot from the previously created PVC named example-pvc.

kubectl create -f examples/snaps-snapshot-from-pvc-workload.yaml
volumesnapshot.snapshot.storage.k8s.io/example-snapshot created

Verify that VolumeSnapshot and VolumeSnapshotContent were created, and that READYTOUSE status is true.

kubectl get VolumeSnapshot,VolumeSnapshotContent

NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
volumesnapshot.snapshot.storage.k8s.io/example-snapshot true example-pvc 10Gi example-snapshot-sc snapcontent-3be9e67b-ece7-4f08-8c40-922a4e84247c 2s 7s

NAME DRIVER DELETIONPOLICY AGE
volumesnapshotclass.snapshot.storage.k8s.io/example-snapshot-sc csi.lightbitslabs.com Delete 81s

Stage 4: Create a PVC from the Snapshot created in stage #3, and create a POD that uses it

After your VolumeSnapshot object is bound, you can use that object to provision a new volume that is pre-populated with data from the snapshot.

The volume snapshot content object is used to restore the existing volume to a previous state.

Create a PVC from the previously taken Snapshot named example-snapshot:

kubectl create -f examples/snaps-pvc-from-snapshot-workload.yaml
persistentvolumeclaim/example-pvc-from-snapshot created
pod/example-pvc-from-snapshot-pod created

Verify that PV, PVC were created and in Bounded state, and that POD is in Running state.

kubectl get pv,pvc,pod
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO Delete Bound default/example-pvc example-sc 18m
persistentvolume/pvc-d1d20d2b-7fdd-4775-9107-ab8129841a74 10Gi RWO Delete Bound default/example-pvc-from-snapshot example-sc 2m24s

NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/example-pvc Bound pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO example-sc 18m
persistentvolumeclaim/example-pvc-from-snapshot Bound pvc-d1d20d2b-7fdd-4775-9107-ab8129841a74 10Gi RWO example-sc 2m25s
Note

We see the PV, PVC and PODs from Stage #2 as well.

Stage 5: Create a PVC from the PVC we created in stage #4, and create a POD that uses it

Create a PVC from the previously taken Snapshot named example-snapshot.

kubectl create -f examples/snaps-pvc-from-pvc-workload.yaml
persistentvolumeclaim/example-pvc-from-pvc created
pod/example-pvc-from-pvc-pod created

Verify that PV, PVC were created and in Bounded state, and that POD is in Running state.

kubectl get pv,pvc,pod
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-1fe22ed7-3b7e-4094-95a3-995538659c51 10Gi RWO Delete Bound default/example-pvc-from-pvc example-sc 15s
persistentvolume/pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO Delete Bound default/example-pvc example-sc 5h53m
persistentvolume/pvc-d1d20d2b-7fdd-4775-9107-ab8129841a74 10Gi RWO Delete Bound default/example-pvc-from-snapshot example-sc 5h36m

NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/example-pvc Bound pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO example-sc 5h53m
Note

We see the PV, PVC and PODs from Stages #2 and #4 as well.

Stage 6: Uninstall Snapshot Workloads

Note: Installation must be in reverse order of the deployment.

After each uninstall, we need to verify that all related resources were released before continuing to the next uninstall.

Uninstall pvc-from-pvc:

kubectl delete -f examples/snaps-pvc-from-pvc-workload.yaml
persistentvolumeclaim "example-pvc-from-pvc" deleted
pod "example-pvc-from-pvc-pod" deleted

In order to verify that all resources are deleted, the following command should not generate any output:

kubectl get pv,pvc,pod | grep pvc-from-pvc

Uninstall pvc-from-snapshot:

kubectl delete -f examples/snaps-pvc-from-snapshot-workload.yaml
persistentvolumeclaim "example-pvc-from-snapshot" deleted
pod "example-pvc-from-snapshot-pod" deleted

In order to verify that all resources are deleted, the following command should not generate any output:

kubectl get pv,pvc,pod | grep pvc-from-snapshot

Uninstall snapshot-from-pvc:

kubectl delete -f examples/snaps-snapshot-from-pvc-workload.yaml
volumesnapshot.snapshot.storage.k8s.io "example-snapshot" deleted

In order to verify that all resources are deleted, the following command should not generate any output:

kubectl get VolumeSnapshot,VolumeSnapshotContent | grep snapshot-from-pvc

Uninstall example-pvc:

kubectl delete -f examples/snaps-example-pvc-workload.yaml
persistentvolumeclaim "example-pvc" deleted
pod "example-pod" deleted

Verify that all resources are gone:

kubectl get pv,pvc,pods
No resources found in default namespace.

Delete VolumeSnapshotClass:

kubectl delete -f examples/snaps-example-snapshot-class.yaml
volumesnapshotclass "example-snapshot-sc" deleted