CloudPe
Knowledge Base Compute Managing Volume Snapshots in Kubernetes (CloudPE)
Compute Updated 23 July 2026

Managing Volume Snapshots in Kubernetes (CloudPE)

1. Executive Summary

Kubernetes supports volume snapshots, allowing you to capture the contents of a Persistent Volume at a specific point in time.

  • Snapshots are useful for restoring volume data in case of accidental deletion, corruption, or data loss.
  • Volume snapshots are implemented as Custom Resource Definitions (CRDs) and must be installed on the cluster before use.
  • βœ… Creating a snapshot does not modify or move the source volume’s data.

2. Prerequisites

Before starting, ensure the following:

πŸ“¦ Persistent Volume Claim

  • A PersistentVolumeClaim (PVC) must already exist.
  • See β€œDynamically Provisioning Persistent Volumes” for details.

πŸš€ CSI Snapshotter Version

  • The CSI snapshotter version used must not be higher than release-5.0.

πŸ”§ Required Components

  • VolumeSnapshotClass, VolumeSnapshotContent, and VolumeSnapshot CRDs
  • Snapshot-controller RBAC resources (ClusterRole, ServiceAccount, ClusterRoleBinding, Role, RoleBinding)
  • Snapshot-controller deployment

3. Installing the Custom Resource Definitions

This method follows Infrastructure as Code (IaC) best practices using manifests from the upstream external-snapshotter repository.


πŸ”Ή Phase A: Clone the Repository

  1. Clone the external-snapshotter repository and check out the supported release:
git clone https://github.com/kubernetes-csi/external-snapshotter/
cd ./external-snapshotter
git checkout release-5.0

πŸ”Ή Phase B: Apply the CRDs

  1. Apply the VolumeSnapshotClass, VolumeSnapshotContent, and VolumeSnapshot CRDs:
kubectl apply -f client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
kubectl apply -f client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
kubectl apply -f client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml

πŸ”Ή Phase C: Deploy the Snapshot Controller

  1. Apply the RBAC rules and the snapshot-controller deployment in the kube-system namespace:
kubectl apply -f deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml -n kube-system
kubectl apply -f deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml -n kube-system

These commands create:

  • CRDs for VolumeSnapshotClass, VolumeSnapshotContent, and VolumeSnapshot
  • The required ClusterRole, ServiceAccount, ClusterRoleBinding, Role, and RoleBinding
  • The snapshot-controller deployment


4. Creating a Volume Snapshot


πŸ”Ή Phase A: Define a VolumeSnapshotClass

  1. Create a snapshot-class.yaml file:
vi snapshot-class.yaml
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: mysnapclass
driver: cinder.csi.openstack.org
deletionPolicy: Delete
parameters:
force-create: "true"
  • This defines the volume snapshot class mysnapclass with the deletion policy Delete.
  • Delete removes the underlying storage snapshot along with the VolumeSnapshotContent object when the VolumeSnapshot is deleted.
  • Set the policy to Retain instead to keep both the underlying snapshot and the VolumeSnapshotContent object after the VolumeSnapshot is deleted.
  1. Apply the snapshot class:
kubectl apply -f snapshot-class.yaml

Expected output:

volumesnapshotclass.snapshot.storage.k8s.io/mysnapclass created

πŸ”Ή Phase B: Define a VolumeSnapshot

  1. Create a snapshot.yaml file:
vi snapshot.yaml 
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: mysnapshot
spec:
volumeSnapshotClassName: mysnapclass
source:
persistentVolumeClaimName: mypvc
  • This defines the volume snapshot mysnapshot, based on the mysnapclass snapshot class.
  • It creates a snapshot of the volume bound to PVC mypvc.
  1. Create the volume snapshot:
kubectl create -f snapshot.yaml

Expected output:

volumesnapshot.snapshot.storage.k8s.io/mysnapshot created

πŸ’‘ In the self-service panel, the new snapshot appears under Compute β†’ Volumes β†’ [Volume] β†’ Snapshots.

  • Also you can verify the snapshots with below command

kubectl get vs


5. Deleting a Volume Snapshot

Run the following command:

kubectl delete -f snapshot.yaml

Expected output:

volumesnapshot.snapshot.storage.k8s.io "mysnapshot" deleted

⚠️ Whether the underlying storage snapshot is also removed depends on the deletionPolicy set on the associated VolumeSnapshotClass (Delete vs. Retain).


6. Safety & Recovery

πŸ”’ Data Integrity

  • Creating a snapshot does not alter, move, or delete data on the source volume.
  • Snapshots capture volume state at the moment of creation and can be used to restore data later.

⚠️ Version Compatibility

  • Using a CSI snapshotter version higher than release-5.0 is not supported and may cause the CRDs or snapshot-controller to behave unexpectedly.

πŸ•’ Best Practice

  • Take snapshots on a regular schedule, especially before major changes or upgrades to workloads using the volume.
  • Use the Retain deletion policy for critical volumes so the underlying snapshot survives accidental deletion of the VolumeSnapshot object.

βœ… Summary

  • Volume snapshots let you capture PVC data at a point in time for recovery purposes.
  • Requires:
  • External-snapshotter CRDs and snapshot-controller (version ≀ release-5.0)
  • A VolumeSnapshotClass
  • A VolumeSnapshot referencing an existing PVC
  • Delete snapshots with kubectl delete -f snapshot.yaml when no longer needed.