You are looking at the documentation of a prior release. To read the documentation of the latest release, please
visit here.
How VolumeSnapshot works in Stash
This guide will show you how Stash takes snapshot of PersistentVolumeClaims and restore them from snapshot using Kubernetes VolumeSnapshot API.
Before You Begin
At first, you need to have a Kubernetes cluster and ensure that a CSI driver that implements snapshots is deployed on your cluster. You can find a list of CSI drivers that supports snapshots here. In this guide we are going to use GCE Persistent Disk CSI Driver.
You need to enable the Kubernetes
VolumeSnapshotDataSource
alpha feature via Kubernetes feature gates--feature-gates=VolumeSnapshotDataSource=true
Install
Stash
in your cluster following the steps here.You should be familiar with the following Stash concepts:
You should be also familiar with the following Kubernetes concepts:
How Backup Process Works?
The following diagram shows how Stash creates VolumeSnapshot via Kubernetes native API. Open the image in a new tab to see the enlarged version.
The VolumeSnapshot
process consists of the following steps:
At first, a user creates a
BackupConfiguration
crd which specifies the targeted workload or targeted PVC.Stash operator watches for
BackupConfiguration
crd.When it finds a
BackupConfiguration
crd, it creates aCronJob
to take a periodic backup of the target volumes.The
CronJob
triggers backup on each scheduled time slot by creating aBackupSession
crd.Stash operator watches for
BackupSession
crd.When it finds a
BackupSession
crd, it creates a volume snapshotterJob
to take snapshot of the targeted volumes.The volume snapshotter
Job
createsVolumeSnapshot
crd for each PVC of the target and waits for the CSI driver to complete snapshotting. TheseVolumeSnasphot
crd names follow the following format:
<PVC name>-<BackupSession creation timestamp in Unix epoch seconds>
CSI
external-snapshotter
controller watches forVolumeSnapshot
.When it finds a
VolumeSnapshot
object, it backupsVolumeSnapshot
in the respective cloud storage.Once the snapsotting is completed, Stash Operator updates the
status.phase
field of theBackupSession
crd.
How Restore Process Works?
The following diagram shows how Stash restores PersistentVolumeClaims from snapshot using Kubernetes VolumeSnapshot API. Open the image in a new tab to see the enlarged version.
The restore process consists of the following steps:
At first, a user creates a
RestoreSession
crd which specifies thevolumeClaimTemplates
.VolumeClaimTemplates
hold the information aboutVolumeSnapshot
.Stash operator watches for
RestoreSession
crd.When it finds a
RestoreSession
crd, it creates a RestoreJob
to restore PVC from the snapshot.The restore
Job
creates PVC withspec.dataSource
field set to the respective VolumeSnapshot name.CSI
external-snapshotter
controller watches for PVC.When it finds a new PVC with
spec.dataSource
field set, it reads the information about theVolumeSnapshot
.The controller downloads the respective data from the cloud and populate the PVC with it.
Once restore process is completed, the Stash operator updates the
status.phase
field of theBackupSession
crd.