Deploying Snapshot and Clones Workloads

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.

For Helm to deploy the snaps chart in stages, we introduce the mandatory variable snaps.stage The chart supports the following stages:

  • snapshot-class

  • example-pvc

  • snapshot-from-pvc

  • pvc-from-snapshot

  • pvc-from-pvc

Stage 1: Create VolumeSnapshotClass

Create a VolumeSnapshotClass:

helm install \
--set snaps.enabled=true \
--set snaps.stage=snapshot-class \
lb-csi-workload-snaps-snapshot-class \
lightbits-helm-repo/lb-csi-workload-examples

Stage 2: Create Example PVC and POD

Running the following command:

helm install \
--set snaps.enabled=true \
--set snaps.stage=example-pvc \
lb-csi-workload-snaps-example-pvc \
lightbits-helm-repo/lb-csi-workload-examples

Will output:

NAME: lb-csi-workload-snaps-example-pvc
LAST DEPLOYED: Sun Feb 21 16:09:02 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

Verify that PV, PVC are created and in Bounded state, and that 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.

helm install \
--set snaps.enabled=true \
--set snaps.stage=snapshot-from-pvc \
lb-csi-workload-snaps-snapshot-from-pvc \
lightbits-helm-repo/lb-csi-workload-examples

Will output:

NAME: lb-csi-workload-snaps-snapshot-from-pvc
LAST DEPLOYED: Tue Feb 23 13:11:16 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

Verify that VolumeSnapshot and VolumeSnapshotContent were created, and 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-b710e398-eaa5-45be-bbdc-db74d799e5cc 3m40s 3m49s

NAME READYTOUSE RESTORESIZE DELETIONPOLICY DRIVER VOLUMESNAPSHOTCLASS VOLUMESNAPSHOT AGE
volumesnapshotcontent.snapshot.storage.k8s.io/snapcontent-b710e398-eaa5-45be-bbdc-db74d799e5cc true 10737418240 Delete csi.lightbitslabs.com example-snapshot-sc example-snapshot 3m49s

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

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

helm install \
--set snaps.enabled=true \
--set snaps.stage=pvc-from-snapshot \
lb-csi-workload-snaps-pvc-from-snapshot \
lightbits-helm-repo/lb-csi-workload-examples

Will output:

NAME: lb-csi-workload-snaps-pvc-from-snapshot
LAST DEPLOYED: Tue Feb 23 13:16:26 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

Verify that PV, PVC are 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 created in Stage 3 and create a POD that uses it

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

helm install \
--set snaps.enabled=true \
--set snaps.stage=pvc-from-pvc \
lb-csi-workload-snaps-pvc-from-pvc \
lightbits-helm-repo/lb-csi-workload-examples

Will output:

NAME: lb-csi-workload-snaps-pvc-from-pvc
LAST DEPLOYED: Tue Feb 23 13:16:26 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

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

If we list the releases installed, we will see:

helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
lb-csi-workload-sc default 1 2021-02-23 08:06:39.915046 +0200 IST deployed lb-csi-workload-examples-0.1.0 1.4.0
lb-csi-workload-snaps-example-pvc default 1 2021-02-23 12:59:55.458252038 +0200 IST deployed lb-csi-workload-examples-0.1.0 1.4.0
lb-csi-workload-snaps-pvc-from-pvc default 1 2021-02-23 18:52:41.391731359 +0200 IST deployed lb-csi-workload-examples-0.1.0 1.4.0
lb-csi-workload-snaps-pvc-from-snapshot default 1 2021-02-23 13:16:26.020897186 +0200 IST deployed lb-csi-workload-examples-0.1.0 1.4.0
lb-csi-workload-snaps-snapshot-from-pvc default 1 2021-02-23 13:11:16.746865829 +0200 IST deployed lb-csi-workload-examples-0.1.0 1.4.0

The 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:

helm uninstall lb-csi-workload-snaps-pvc-from-pvc

In order to verify that all resources are deleted, the following command should return no entry:

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

Uninstall pvc-from-snapshot:

helm uninstall lb-csi-workload-snaps-pvc-from-snapshot

In order to verify that all resources are deleted, the following command should return no entry:

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

Uninstall snapshot-from-pvc:

helm uninstall lb-csi-workload-snaps-snapshot-from-pvc

In order to verify that all resources are deleted, the following command should return no entry:

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

Uninstall example-pvc:

helm uninstall lb-csi-workload-snaps-example-pvc

Verify that all resources are gone:

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

Delete VolumeSnapshotClass:

helm uninstall lb-csi-workload-snaps-snapshot-class