VolumeSnapshot Using KubeStash
This guide will give you an overview of how VolumeSnapshot process works in KubeStash.
How Backup Process Works?
The following diagram shows how KubeStash 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
Secret
with access credentials of the backend where the backed-up data will be stored.Then, she creates a
BackupStorage
custom resource that specifies the backend information, along with theSecret
containing the credentials needed to access the backend.KubeStash operator watches for
BackupStorage
custom resources. When it finds aBackupStorage
object, it initializes theBackupStorage
by uploading themetadata.yaml
file to the target storage.Then, she creates a
BackupConfiguration
custom resource that specifies the targeted workload/PVC, the Addon info with a specified task, etc. It also provides information about one or more repositories, each indicating a path and aBackupStorage
for storing the metadata.KubeStash operator watches for
BackupConfiguration
custom resources.Once the KubeStash operator finds a
BackupConfiguration
object, it createsRepository
with the information specified in the BackupConfiguration.KubeStash operator watches for
Repository
custom resources. When it finds theRepository
object, it InitializesRepository
by uploadingrepository.yaml
file to thespec.sessions[*].repositories[*].directory
path specified in theBackupConfiguration
.Then, it creates a
CronJob
with the schedule specified inBackupConfiguration
to trigger backup periodically.On the next scheduled slot, the
CronJob
triggers a backup by creating aBackupSession
custom resource.KubeStash operator watches for
BackupSession
custom resources.When it finds a
BackupSession
object, it creates aSnapshot
custom resource for eachRepository
specified in the respective session of theBackupConfiguration
.Then, it resolves the respective
Addon
andFunction
and prepares a volume snapshotterJob
definition.Then, It creates a volume snapshotter
Job
to capture snapshots of the targeted volumes.The volume snapshotter
Job
creates aVolumeSnapshot
object for each Persistent Volume Claim (PVC) associated the target and waits for the Container Storage Interface (CSI) driver to complete snapshotting. The VolumeSnapshot(s) are created with the following naming format:<PVC name>-<BackupSession creation timestamp in Unix epoch seconds>
Container Storage Interface (CSI)
external-snapshotter
controller watches forVolumeSnapshot
resources.When it finds a
VolumeSnapshot
object, it backupsVolumeSnapshot
to the respective cloud storage.After the snapshotting process is completed, the volume snapshotter
Job
updates thestatus.components[*]
field of theSnapshot
resources withVolumeSnapshot
information.
How Restore Process Works?
The following diagram shows how KubeStash 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
custom resource that specifies thevolumeClaimTemplates
, Addon info with a specified task, and aDataSource
that determines theSnapshot
from which the data will be restored.KubeStash operator watches for
RestoreSession
custom resources.Once it finds a
RestoreSession
object, it resolves the respectiveAddon
andFunction
and prepares a restore Job definition.Then, it creates a Restore
Job
to restorePVC
from thevolumeSnapshot
.The restore job retrieves
VolumeSnapshot
information from the Snapshot. Then it creates PVCs based on thevolumeClaimTemplates
withspec.dataSourceRef
field set to the respectiveVolumeSnapshot
name.Container Storage Interface (CSI)
external-snapshotter
controller watches forPVCs
.When it finds a new
PVC
withspec.dataSource
field set, it reads the information about theVolumeSnapshot
.The controller downloads the respective data from the cloud and populates the
PVC
.Finally, when the restore process is completed, the restore
Job
updates thestatus.components[*]
field of theRestoreSession
with restore information of the target application components.