liveBook · Manning

Volumesnapshot

As explained in Kubernetes in Action, Second Edition

A volume snapshot artifact is a point-in-time copy of data stored on a persistent volume.

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

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains class creation, snapshot requests, readiness checks, content representation, and claim restoration, but not CSI internals.
Examples
Demonstrates quiz-data snapshots, kubectl get vs status output, and restoration into quiz-data-from-snapshot.
What it assumes
Assumes familiarity with PersistentVolumes and PersistentVolumeClaims, while introducing snapshot classes, content, readiness, and restoration details.
What you can do after
Operate/configure snapshots with VolumeSnapshotClass and kubectl, then restore a PersistentVolumeClaim from a ready snapshot.
How it connects
Connects PersistentVolumes, PersistentVolumeClaims, VolumeSnapshotClass, VolumeSnapshotContent, CSI drivers, StorageClasses, and pods.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.