This driver implements basic volume snapshotting functionality using the external snapshotter sidecar and creates snapshots of BSU volumes using the VolumeSnapshot
custom resources.
In Kubernetes versions 1.21 and later, VolumeSnapshotDataSource has been enabled by default. If your cluster is running Kubernetes 1.21 or higher, you do not need to manually set the --feature-gates=VolumeSnapshotDataSource=true flag, as it should already be enabled. The snapshot feature will work out of the box without the need for additional configuration at the API server level.
In Kubernetes versions 1.20 and earlier, the VolumeSnapshotDataSource feature is not enabled by default, so you would need to manually set the --feature-gates=VolumeSnapshotDataSource=true flag on the API server to enable volume snapshots.
You can apply the CRDs (if not already installed) using the following commands:
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-8.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-8.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-8.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
This will set up the necessary CRDs for volume snapshotting.
The snapshot controller is responsible for managing snapshots in your cluster. You can install it using the following commands:
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-8.0/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-8.0/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml
This ensures that the snapshot controller is set up correctly to manage volume snapshots and restorations.
After applying the CRDs and deploying the snapshot controller, ensure everything is set up correctly:
kubectl get crds | grep snapshot
kubectl get pods -n kube-system | grep snapshot
kubectl get volumesnapshotclass
kubectl get volumesnapshot
- Create the
StorageClass
andVolumeSnapshotClass
:
kubectl apply -f specs/classes/
- Create a sample app and the
PersistentVolumeClaim
:
kubectl apply -f specs/app/
- Validate the volume was created and
volumeHandle
contains an BSU volumeID:
kubectl describe pv
- Validate the pod successfully wrote data to the volume, taking note of the timestamp of the first entry:
kubectl exec -it app cat /data/out.txt
- Create a
VolumeSnapshot
referencing thePersistentVolumeClaim
name:
kubectl apply -f specs/snapshot/
- Wait for the
Ready To Use: true
attribute of theVolumeSnapshot
:
kubectl describe volumesnapshot.snapshot.storage.k8s.io bsu-volume-snapshot
- Delete the existing app:
kubectl delete -f specs/app/
- Restore a volume from the snapshot with a
PersistentVolumeClaim
referencing theVolumeSnapshot
in itsdataSource
:
kubectl apply -f specs/snapshot-restore/
- Validate the new pod has the restored data by comparing the timestamp of the first entry to that of in step 4:
kubectl exec -it app cat /data/out.txt
- Cleanup resources:
kubectl delete -f specs/snapshot-restore
kubectl delete -f specs/snapshot
kubectl delete -f specs/classes