- Kubernetes 1.13+ (CSI 1.0).
- The aws-ebs-csi-driver installed.
- The external snapshotter installed.
- The
VolumeSnapshotDataSource
is set in--feature-gates=
in thekube-apiserver
specification. This feature is enabled by default from Kubernetes v1.17+.
This example shows you how to create a snapshot and restore an EBS PersistentVolume
.
-
Create the
StorageClass
andVolumeSnapshotClass
:$ kubectl apply -f manifests/classes/ volumesnapshotclass.snapshot.storage.k8s.io/csi-aws-vsc created storageclass.storage.k8s.io/ebs-sc created
-
Deploy the provided pod on your cluster along with the
PersistentVolumeClaim
:$ kubectl apply -f manifests/app/ persistentvolumeclaim/ebs-claim created pod/app created
-
Validate the
PersistentVolumeClaim
is bound to yourPersistentVolume
.$ kubectl get pvc ebs-claim NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE ebs-claim Bound pvc-c2e5476c-d9f5-4a49-bbb2-9dfdb27db4c8 4Gi RWO ebs-sc 43s
-
Validate the pod successfully wrote data to the volume, taking note of the timestamp of the first entry:
$ kubectl exec app -- cat /data/out.txt Thu Feb 24 04:07:57 UTC 2022 ...
-
Create a
VolumeSnapshot
referencing thePersistentVolumeClaim
name:$ kubectl apply -f manifests/snapshot/ volumesnapshot.snapshot.storage.k8s.io/ebs-volume-snapshot created
-
Wait for the
Ready To Use: true
attribute of theVolumeSnapshot
:$ kubectl describe volumesnapshot.snapshot.storage.k8s.io ebs-volume-snapshot ... Status: Bound Volume Snapshot Content Name: snapcontent-333215f5-ab85-42b8-b4fc-27a6cba0cc19 Creation Time: 2022-02-24T04:09:51Z Ready To Use: true Restore Size: 4Gi
-
Delete the existing app:
$ kubectl delete -f manifests/app/ persistentvolumeclaim "ebs-claim" deleted pod "app" deleted
-
Restore a volume from the snapshot with a
PersistentVolumeClaim
referencing theVolumeSnapshot
in itsdataSource
:$ kubectl apply -f manifests/snapshot-restore/ persistentvolumeclaim/ebs-snapshot-restored-claim created pod/app created
-
Validate the new pod has the restored data by comparing the timestamp of the first entry to that of in step 4:
$ kubectl exec app -- cat /data/out.txt Thu Feb 24 04:07:57 UTC 2022 ...
-
Cleanup resources:
$ kubectl delete -f manifests/snapshot-restore persistentvolumeclaim "ebs-snapshot-restored-claim" deleted pod "app" deleted
$ kubectl delete -f manifests/snapshot volumesnapshot.snapshot.storage.k8s.io "ebs-volume-snapshot" deleted
$ kubectl delete -f manifests/classes volumesnapshotclass.snapshot.storage.k8s.io "csi-aws-vsc" deleted storageclass.storage.k8s.io "ebs-sc" deleted