A VolumeSnapshot is a point-in-time copy of data stored on a persistent volume. It supports backup and cloning, provided the underlying CSI driver supports snapshots. section 10.4 section 10.4.2
Create a VolumeSnapshotClass first, then create a VolumeSnapshot that names the class and identifies the source PersistentVolumeClaim. Kubernetes and the CSI driver represent the resulting snapshot through VolumeSnapshotContent. section 10.4.2 section 10.4.2
Listing 10.13 Requesting a volume snapshot by a creating a VolumeSnapshot object
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: quiz-data-1 #1
spec:
volumeSnapshotClassName: pd-csi #2
source: #3
persistentVolumeClaimName: quiz-data #3
Use this manifest pattern to request a snapshot of the quiz-data PersistentVolumeClaim. section 10.4.2
A snapshot may not be immediately usable. Check its status with kubectl get vs and wait for READYTOUSE to become true before restoring data from it. section 10.4.2
Restore a claim from a snapshot
Create a new PersistentVolumeClaim whose dataSourceRef names the VolumeSnapshot, sets apiGroup to snapshot.storage.k8s.io, and requests storage. A default StorageClass may provide the storage; with WaitForFirstConsumer, creating a pod can start restoration. section 10.4.3 section 10.4.3
Listing 10.14 Creating a PersistentVolumeClaim from a VolumeSnapshot
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: quiz-data-from-snapshot
spec:
resources:
requests:
storage: 1Gi
accessModes:
- ReadWriteOncePod
dataSourceRef: #1
apiGroup: snapshot.storage.k8s.io #1
kind: VolumeSnapshot #1
name: quiz-data-1 #1
Use this claim manifest pattern to restore quiz-data-1 into quiz-data-from-snapshot. section 10.4.3
