Skip to content

Commit

Permalink
Fix mongo kubestash backup doc rendering (#673)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
Signed-off-by: sayedppqq <[email protected]>
Co-authored-by: sayedppqq <[email protected]>
  • Loading branch information
tamalsaha and sayedppqq authored Sep 16, 2024
1 parent d27a432 commit 2fe7040
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ In this tutorial, we are going to show how you can configure a backup blueprint

## Before You Begin

- At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster.
- Install KubeStash Enterprise in your cluster following the steps [here](https://stash.run/docs/latest/setup/install/stash/).
- Install KubeDB in your cluster following the steps [here](/docs/setup/README.md).
- If you are not familiar with how Stash backup and restore MongoDB databases, please check the following guide [here](/docs/guides/mongodb/backup/stash/overview/index.md).
- If you are not familiar with how auto-backup works in Stash, please check the following guide [here](https://stash.run/docs/latest/guides/auto-backup/overview/).
- If you are not familiar with the available auto-backup options for databases in Stash, please check the following guide [here](https://stash.run/docs/latest/guides/auto-backup/database/).
- At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using `Minikube` or `Kind`.
- Install `KubeDB` in your cluster following the steps [here](/docs/setup/README.md).
- Install `KubeStash` in your cluster following the steps [here](https://kubestash.com/docs/latest/setup/install/kubestash).
- Install KubeStash `kubectl` plugin following the steps [here](https://kubestash.com/docs/latest/setup/install/kubectl-plugin/).
- If you are not familiar with how KubeStash backup and restore `MongoDB` databases, please check the following guide [here](/docs/guides/mongodb/backup/kubestash/overview/index.md).

You should be familiar with the following `KubeStash` concepts:

- [BackupBlueprint](https://stash.run/docs/latest/concepts/crds/backupblueprint/)
- [BackupConfiguration](https://stash.run/docs/latest/concepts/crds/backupconfiguration/)
- [BackupSession](https://stash.run/docs/latest/concepts/crds/backupsession/)
- [Repository](https://stash.run/docs/latest/concepts/crds/repository/)
- [Function](https://stash.run/docs/latest/concepts/crds/function/)
- [Task](https://stash.run/docs/latest/concepts/crds/task/)
- [BackupBlueprint](https://kubestash.com/docs/latest/concepts/crds/backupblueprint/)
- [BackupConfiguration](https://kubestash.com/docs/latest/concepts/crds/backupconfiguration/)
- [BackupSession](https://kubestash.com/docs/latest/concepts/crds/backupsession/)
- [BackupStorage](https://kubestash.com/docs/latest/concepts/crds/backupstorage/)
- [Function](https://kubestash.com/docs/latest/concepts/crds/function/)
- [Addon](https://kubestash.com/docs/latest/concepts/crds/addon/)

To keep things isolated, we are going to use a separate namespace called `demo` throughout this tutorial. Create `demo` namespace if you haven't created yet.

Expand All @@ -48,7 +47,7 @@ namespace/demo created

So we can also take backup any MongoDB database of any namespace just by adding few annotations to our MongoDB CRD. Then, KubeStash will automatically create a `BackupConfiguration` according to the template to backup the database.

We are going to store our backed up data into a S3 bucket. At first, we need to create a secret with S3 credentials then we need to create a `BackupStorage` crd. If you want to use a different backend, please read the respective backend configuration doc from [here](https://stash.run/docs/latest/guides/backends/overview/).
We are going to store our backed up data into a S3 bucket. At first, we need to create a secret with S3 credentials then we need to create a `BackupStorage` crd. If you want to use a different backend, please read the respective backend configuration doc from [here](https://kubestash.com/docs/latest/guides/backends/overview/).

### Create Storage Secret:

Expand Down Expand Up @@ -81,7 +80,7 @@ spec:
bucket: kubestash-testing
region: us-east-1
prefix: demo
secret: s3-secret
secretName: s3-secret
usagePolicy:
allowedNamespaces:
from: All
Expand Down Expand Up @@ -147,28 +146,30 @@ spec:
backupConfigurationTemplate:
deletionPolicy: OnDelete
backends:
- name: s3-backend
storageRef:
namespace: ${storageNamespace}
name: ${storageName}
retentionPolicy:
name: backup-rp
namespace: demo
- name: s3-backend
storageRef:
namespace: ${storageNamespace}
name: ${storageName}
retentionPolicy:
name: backup-rp
namespace: demo
sessions:
- name: frequent
scheduler:
schedule: ${scheduleTime}
repositories:
- name: ${repoName}
backend: s3-backend
directory: ${backupPath}
encryptionSecret:
name: encry-secret
namespace: demo
addon:
name: mongodb-addon
tasks:
- name: LogicalBackup
- name: frequent
scheduler:
jobTemplate:
backoffLimit: 1
schedule: ${scheduleTime}
repositories:
- name: ${repoName}
backend: s3-backend
directory: ${backupPath}
encryptionSecret:
name: encry-secret
namespace: demo
addon:
name: mongodb-addon
tasks:
- name: LogicalBackup
```

Here, we define a template for `BackupConfiguration`. Notice the `backends` and `sessions` fields of `backupConfigurationTemplate` section. We have used some variables in form of `${VARIABLE_NAME}`. KubeStash will automatically resolve those variables from the database annotations information to make `BackupConfiguration` according to that databases need.
Expand All @@ -180,7 +181,7 @@ Let's create the `BackupBlueprint` we have shown above,
backupblueprint.core.kubestash.com/sample-blueprint created
```

Now, we are ready to backup our MongoDB databases using few annotations. You can check available auto-backup annotations for a databases from [here](https://stash.run/docs/latest/guides/auto-backup/database/#available-auto-backup-annotations-for-database).
Now, we are ready to backup our `MongoDB` databases using few annotations.

### Create Database

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ spec:
name: mongodb-addon
tasks:
- name: LogicalBackup
containerRuntimeSettings:
resources:
requests:
cpu: "200m"
memory: "1Gi"
limits:
cpu: "200m"
memory: "1Gi"
containerRuntimeSettings:
resources:
requests:
cpu: "200m"
memory: "1Gi"
limits:
cpu: "200m"
memory: "1Gi"
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ spec:
name: mongodb-addon
tasks:
- name: LogicalBackup
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ spec:
name: mongodb-addon
tasks:
- name: LogicalBackupRestoress
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In this section, we are going to show you how to customize the backup process. H

### Passing arguments to the backup process

KubeStash MongoDB addon uses [mongoump](https://docs.mongodb.com/database-tools/mongodump/) for backup. You can pass arguments to the `mongodump` through `args` param under `spec.sessions.addon.task.params` section.
KubeStash MongoDB addon uses [mongoump](https://docs.mongodb.com/database-tools/mongodump/) for backup. You can pass arguments to the `mongodump` through `args` param under `spec.sessions.addon.tasks[0].params` section.

The below example shows how you can pass the `--db testdb` to take backup for a specific mongodb databases named `testdb`.

Expand All @@ -44,18 +44,20 @@ spec:
name: s3-storage
retentionPolicy:
name: backup-rp
namespace: demo
namespace: demo
sessions:
- name: frequent
scheduler:
schedule: "*/5 * * * *"
jobTemplate:
backoffLimit: 1
repositories:
- name: s3-repo
backend: s3-backend
directory: /mongodb
encryptionSecret:
name: encry-secret
namespace: demo
name: encry-secret
namespace: demo
addon:
name: mongodb-addon
tasks:
Expand All @@ -68,7 +70,7 @@ spec:

### Running backup job as a specific user

If your cluster requires running the backup job as a specific user, you can provide `securityContext` under `spec.sessions.addon.tasks.jobTemplate.spec` section. The below example shows how you can run the backup job as the root user.
If your cluster requires running the backup job as a specific user, you can provide `securityContext` under `spec.sessions.addon.tasks[0].jobTemplate.spec` section. The below example shows how you can run the backup job as the root user.

```yaml
apiVersion: core.kubestash.com/v1alpha1
Expand All @@ -89,32 +91,34 @@ spec:
name: s3-storage
retentionPolicy:
name: backup-rp
namespace: demo
namespace: demo
sessions:
- name: frequent
scheduler:
jobTemplate:
backoffLimit: 1
schedule: "*/5 * * * *"
repositories:
- name: s3-repo
backend: s3-backend
directory: /mongodb
encryptionSecret:
name: encry-secret
namespace: demo
name: encry-secret
namespace: demo
addon:
name: mongodb-addon
tasks:
- name: LogicalBackup
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
```

### Specifying Memory/CPU limit/request for the backup job

If you want to specify the Memory/CPU limit/request for your backup job, you can specify `resources` field under `spec.sessions.addon.tasks.containerRuntimeSettings` section.
If you want to specify the Memory/CPU limit/request for your backup job, you can specify `resources` field under `spec.sessions.addon.containerRuntimeSettings` section.

```yaml
apiVersion: core.kubestash.com/v1alpha1
Expand All @@ -135,30 +139,32 @@ spec:
name: s3-storage
retentionPolicy:
name: backup-rp
namespace: demo
namespace: demo
sessions:
- name: frequent
scheduler:
jobTemplate:
backoffLimit: 1
schedule: "*/3 * * * *"
repositories:
- name: s3-repo
backend: s3-backend
directory: /mongodb
encryptionSecret:
name: encry-secret
namespace: demo
name: encry-secret
namespace: demo
addon:
name: mongodb-addon
tasks:
- name: LogicalBackup
containerRuntimeSettings:
resources:
requests:
cpu: "200m"
memory: "1Gi"
limits:
cpu: "200m"
memory: "1Gi"
containerRuntimeSettings:
resources:
requests:
cpu: "200m"
memory: "1Gi"
limits:
cpu: "200m"
memory: "1Gi"
```

## Customizing Restore Process
Expand All @@ -167,7 +173,7 @@ KubeStash also uses `mongorestore` during the restore process. In this section,

### Passing arguments to the restore process

Similar to the backup process, you can pass arguments to the restore process through the `args` params under `spec.addon.task.params` section. This example will restore data from database `testdb`.
Similar to the backup process, you can pass arguments to the restore process through the `args` params under `spec.addon.tasks[0].params` section. This example will restore data from database `testdb`.

```yaml
apiVersion: core.kubestash.com/v1alpha1
Expand Down Expand Up @@ -206,9 +212,7 @@ demo s3-repo-mg-frequent-1702291682 s3-repo frequent 2023-12-11T
demo s3-repo-mg-frequent-1702291685 s3-repo frequent 2023-12-11T10:49:10Z Delete Succeeded 82m
```

>You can also filter the snapshots as shown in the guide [here](https://stash.run/docs/latest/concepts/crds/snapshot/#working-with-snapshot).

The below example shows how you can pass a specific snapshot id through the `snapshots` filed of `rules` section.
The below example shows how you can pass a specific snapshot id through the `snapshots` filed of `spec.dataSource` section.

```yaml
apiVersion: core.kubestash.com/v1alpha1
Expand Down Expand Up @@ -256,22 +260,22 @@ spec:
snapshot: latest
repository: s3-repo
encryptionSecret:
name: encry-secret
name: encry-secret
namespace: demo
addon:
name: mongodb-addon
tasks:
- name: LogicalBackupRestoress
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
jobTemplate:
spec:
securityContext:
runAsUser: 0
runAsGroup: 0
```

### Specifying Memory/CPU limit/request for the restore job

Similar to the backup process, you can also provide `resources` field under the `spec.addon.tasks.containerRuntimeSettings` section to limit the Memory/CPU for your restore job.
Similar to the backup process, you can also provide `resources` field under the `spec.addon.containerRuntimeSettings` section to limit the Memory/CPU for your restore job.

```yaml
apiVersion: core.kubestash.com/v1alpha1
Expand All @@ -295,14 +299,14 @@ spec:
name: mongodb-addon
tasks:
- name: LogicalBackupRestoress
containerRuntimeSettings:
resources:
requests:
cpu: "200m"
memory: "1Gi"
limits:
cpu: "200m"
memory: "1Gi"
containerRuntimeSettings:
resources:
requests:
cpu: "200m"
memory: "1Gi"
limits:
cpu: "200m"
memory: "1Gi"
```

## Cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
bucket: kubestash-testing
region: us-east-1
prefix: demo-replicaset
secret: s3-secret
secretName: s3-secret
usagePolicy:
allowedNamespaces:
from: All
Expand Down
Loading

0 comments on commit 2fe7040

Please sign in to comment.