Warning
This page was translated from the original Japanese version by PLaMo Translate. The Japanese version is authoritative; the English translation may contain inaccuracies.
Persistent Storage Snapshots
Persistent storage snapshots provide a convenient mechanism for backing up and restoring data. They allow you to create copies of volumes at specific points in time, enabling you to revert volumes to previous states or create new volumes. Once created, snapshots maintain their state even if the underlying volume is updated. This makes them ideal for use cases such as backups and versioning.
This documentation explains how to create, manage, and utilize snapshots.
Creating a Snapshot from a Volume
You create a snapshot of the current state of an existing volume.
Suppose you have the following PersistentVolumeClaim (PVC): You want to create a snapshot for this PVC named hello-sample-pvc.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hello-sample-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Mi
storageClassName: standard-rwo-<organization-name>
volumeMode: Filesystem
- Create a VolumeSnapshot resource manifest specifying the name of the PVC from which to create the snapshot.
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: hello-snapshot-v1
spec:
source:
persistentVolumeClaimName: hello-sample-pvc
Applying this manifest to Kubernetes will save the volume’s state at that moment, creating a new snapshot.
- You can verify whether the snapshot was created successfully using
kubectl get volumesnapshots.
$ kubectl get volumesnapshots
NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
hello-snapshot-v1 true hello-sample-pvc ...Mi trident snapcontent-.......... ..d ..d
A successfully created snapshot will have the READYTOUSE field set to true. In this case, the snapshot from the PersistentVolumeClaim was created successfully.
Note
If
READYTOUSEis nottrue, the creation process is not yet complete. Creating snapshots may take several seconds to a minute as data is being copied.
Restoring a Volume from a Snapshot
You can create a new volume from a snapshot by writing a PVC manifest as shown below.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hello-sample-pvc-restored
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 20Mi
storageClassName: standard-rwo-<organization-name>
dataSource:
name: hello-snapshot-v1
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io