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.yamlStage 2: Create Example PVC and POD
Running the following command:
kubectl create -f examples/snaps-example-pvc-workload.yamlpersistentvolumeclaim/example-pvc createdpod/example-pod createdVerify that PV, PVC are created and in Bounded state and POD is in Running state.
kubectl get pv,pvc,podsNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEpersistentvolume/pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO Delete Bound default/example-pvc example-sc 57sNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEpersistentvolumeclaim/example-pvc Bound pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO example-sc 58sNAME READY STATUS RESTARTS AGEpod/example-pod 1/1 Running 0 58sStage 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 createdVerify that VolumeSnapshot and VolumeSnapshotContent were created, and that READYTOUSE status is true.
kubectl get VolumeSnapshot,VolumeSnapshotContentNAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGEvolumesnapshot.snapshot.storage.k8s.io/example-snapshot true example-pvc 10Gi example-snapshot-sc snapcontent-3be9e67b-ece7-4f08-8c40-922a4e84247c 2s 7sNAME DRIVER DELETIONPOLICY AGEvolumesnapshotclass.snapshot.storage.k8s.io/example-snapshot-sc csi.lightbitslabs.com Delete 81sStage 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 createdpod/example-pvc-from-snapshot-pod createdVerify that PV, PVC were created and in Bounded state, and that POD is in Running state.
kubectl get pv,pvc,podNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEpersistentvolume/pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO Delete Bound default/example-pvc example-sc 18mpersistentvolume/pvc-d1d20d2b-7fdd-4775-9107-ab8129841a74 10Gi RWO Delete Bound default/example-pvc-from-snapshot example-sc 2m24sNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEpersistentvolumeclaim/example-pvc Bound pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO example-sc 18mpersistentvolumeclaim/example-pvc-from-snapshot Bound pvc-d1d20d2b-7fdd-4775-9107-ab8129841a74 10Gi RWO example-sc 2m25sNAME READY STATUS RESTARTS AGEpod/example-pod 1/1 Running 0 18mpod/example-pvc-from-snapshot-pod 1/1 Running 0 2m25sWe 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 createdpod/example-pvc-from-pvc-pod createdVerify that PV, PVC were created and in Bounded state, and that POD is in Running state.
kubectl get pv,pvc,podNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEpersistentvolume/pvc-1fe22ed7-3b7e-4094-95a3-995538659c51 10Gi RWO Delete Bound default/example-pvc-from-pvc example-sc 15spersistentvolume/pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO Delete Bound default/example-pvc example-sc 5h53mpersistentvolume/pvc-d1d20d2b-7fdd-4775-9107-ab8129841a74 10Gi RWO Delete Bound default/example-pvc-from-snapshot example-sc 5h36mNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEpersistentvolumeclaim/example-pvc Bound pvc-797e45c0-2333-47ce-9a5e-2bb46b101163 10Gi RWO example-sc 5h53mpersistentvolumeclaim/example-pvc-from-pvc Bound pvc-1fe22ed7-3b7e-4094-95a3-995538659c51 10Gi RWO example-sc 23spersistentvolumeclaim/example-pvc-from-snapshot Bound pvc-d1d20d2b-7fdd-4775-9107-ab8129841a74 10Gi RWO example-sc 5h36mNAME READY STATUS RESTARTS AGEpod/example-pod 1/1 Running 0 5h53mpod/example-pvc-from-pvc-pod 1/1 Running 0 23spod/example-pvc-from-snapshot-pod 1/1 Running 0 5h36mWe 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.yamlpersistentvolumeclaim "example-pvc-from-pvc" deletedpod "example-pvc-from-pvc-pod" deletedIn order to verify that all resources are deleted, the following command should not generate any output:
kubectl get pv,pvc,pod | grep pvc-from-pvcUninstall pvc-from-snapshot:
kubectl delete -f examples/snaps-pvc-from-snapshot-workload.yaml persistentvolumeclaim "example-pvc-from-snapshot" deletedpod "example-pvc-from-snapshot-pod" deletedIn order to verify that all resources are deleted, the following command should not generate any output:
kubectl get pv,pvc,pod | grep pvc-from-snapshotUninstall snapshot-from-pvc:
kubectl delete -f examples/snaps-snapshot-from-pvc-workload.yaml volumesnapshot.snapshot.storage.k8s.io "example-snapshot" deletedIn order to verify that all resources are deleted, the following command should not generate any output:
kubectl get VolumeSnapshot,VolumeSnapshotContent | grep snapshot-from-pvcUninstall example-pvc:
kubectl delete -f examples/snaps-example-pvc-workload.yaml persistentvolumeclaim "example-pvc" deletedpod "example-pod" deletedVerify that all resources are gone:
kubectl get pv,pvc,podsNo resources found in default namespace.Delete VolumeSnapshotClass:
kubectl delete -f examples/snaps-example-snapshot-class.yamlvolumesnapshotclass "example-snapshot-sc" deleted