Backup and Restore Cluster Resources using KubeStash
This guide will show you how KubeStash backs up and restores manifests of cluster resources.
Before You Begin
- You should be familiar with the following
KubeStash
concepts:
How Backup Process Works
The following diagram shows how KubeStash takes backup of the manifests of cluster resources. Open the image in a new tab to see the enlarged version.
The backup process consists of the following steps:
At first, a user creates a
Secret
. This secret holds the credentials to access 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 into the target storage.Then, she creates a
BackupConfiguration
custom resource that specifies the targeted workload, 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 backed-up data.KubeStash operator watches for
BackupConfiguration
objects.Once the KubeStash operator finds a
BackupConfiguration
object, it createsRepository
with the information specified in theBackupConfiguration
. For targeting backup cluster resources, the params section under theaddon.tasks
provides multiple filtering options.KubeStash operator watches for
Repository
custom resources. When it finds theRepository
object, it InitializesRepository
by uploadingrepository.yaml
file into thespec.sessions[*].repositories[*].directory
path specified inBackupConfiguration
.Then, it creates a
CronJob
for each session 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 theBackupConfiguration
.Then it resolves the respective
Addon
andFunction
and prepares backupJob
(s) definition.The backup
Job
(s) collect and store the cluster resource’s manifests.After the backup process is completed, the backup
Job
(s) updates thestatus.components[*]
field of theSnapshot
resources with backup information of the target manifest components.
How Restore Process Works
The following diagram shows how KubeStash restores cluster resources from backed up manifests. Open the image in a new tab to see the enlarged version.
The restore process consists of the following steps:
At first, user creates a
RestoreSession
custom resource that specifies the target workload volume(s) where the backed-up data will be restored, theRepository
object that points to aBackupStorage
that holds backend information, and the targetSnapshot
, which will be restored. It also specifies theAddon
info with task to use to restore the volume.KubeStash operator watches for
RestoreSession
custom resources.When it finds a
RestoreSession
custom resource, it resolves the respectiveAddon
andFunction
and prepares a restoreJob
(s) definition.The restore
Job
(s) apply the backed-up manifests to recreate the cluster resources.Finally, when the restore process is completed, the
Job
(s) updates thestatus.components[*]
field of theRestoreSession
with restore information of the target manifest components.