Skip to main content
Version: Preview

Introduction

BackupRepo is the storage repository for backup data. Currently, KubeBlocks supports configuring various object storage services as backup repositories, including OSS (Alibaba Cloud Object Storage Service), S3 (Amazon Simple Storage Service), COS (Tencent Cloud Object Storage), GCS (Google Cloud Storage), OBS (Huawei Cloud Object Storage), MinIO, and other S3-compatible services. Additionally, it also supports using Kubernetes-native PVCs as backup repositories.

You can create multiple BackupRepos to suit different scenarios. For example, based on different businesses, the data of business A is stored in repository A, and the data of business B is stored in repository B. Or you can configure multiple repositories by region to realize geo-disaster recovery. But it is required to specify backup repositories when you create a backup. You can also create a default backup repository and KubeBlocks uses this default repository to store backup data if no specific repository is specified.

Before you start

Make sure you have all the following prepared.

Install MinIO

If you don't have an object storage service from a cloud provider, you can deploy the open-source service MinIO in Kubernetes and use it to configure BackupRepo. If you are using an object storage service provided by a cloud provider, directly skip to Configure BackupRepo.

Steps

  1. Install MinIO in the kb-system namespace.

    helm repo add kubeblocks-apps https://jihulab.com/api/v4/projects/152630/packages/helm/stable
    helm install minio kubeblocks-apps/minio --namespace kb-system --create-namespace --set "extraEnvVars[0].name=MINIO_BROWSER_LOGIN_ANIMATION" --set "extraEnvVars[0].value=off"

    Get the initial username and password:

    # Initial username
    echo $(kubectl get secret --namespace kb-system minio -o jsonpath="{.data.root-user}" | base64 -d)

    # Initial password
    echo $(kubectl get secret --namespace kb-system minio -o jsonpath="{.data.root-password}" | base64 -d)
  2. Generate credentials.

    Access the login page by running kubectl port-forward --namespace kb-system svc/minio 9001:9001 and then accessing 127.0.0.1:9001.

    Once you are logged in to the dashboard, you can generate an access key and secret key.

    backup-and-restore-backup-repo-1

  3. Create a bucket.

    Create a bucket named test-minio for the test.

    backup-and-restore-backup-repo-2 backup-and-restore-backup-repo3

    note

    The access address (endpoint) for the installed MinIO is http://minio.kb-system.svc.cluster.local:9000, which will be used to configure BackupRepo. In this case, kb-system is the name of the namespace where MinIO is installed.

Configure BackupRepo

With object storage services prepared, it's time to configure BackupRepo. KubeBlocks provides two ways for the configuration:

  • Automatic BackupRepo configuration during KubeBlocks installation;
  • Manual BackupRepo configuration for on-demand scenarios.

Access BackupRepo

There are two methods to access remote object storage:

  • Use command-line tools to directly access remote storage.
  • Mount the remote storage to the local system with a CSI driver, allowing the work processes to access the remote storage as if it were local files.

The two access methods are referred to as "Tool" and "Mount". When creating BackupRepo, you can specify the access method through the accessMethod field, which can not be changed after creation.

Generally, it is recommended to use the "Tool" method as it does not require installing an additional CSI driver, thus reducing dependencies.

However, as backup and restore tasks require running in the namespace of the database cluster, using the "Tool" approach automatically synchronizes the necessary credentials for accessing the remote storage as secret resources in those namespaces. These credentials are used by the data transfer tool. If you have concerns about security risks associated with synchronizing secrets in a multi-tenant environment, you can choose to use the "Mount" method.

Automatic BackupRepo configuration

You can specify the BackupRepo information in a YAML configuration file when installing KubeBlocks, and KubeBlocks will create the BackupRepo and automatically install the necessary CSI Driver based on the provided configuration.

  1. Prepare the configuration file.

    Taking AWS S3 as an example, the configuration file backuprepo.yaml is:

    backupRepo:
    create: true
    storageProvider: s3
    config:
    region: cn-northwest-1
    bucket: test-kb-backup
    secrets:
    accessKeyId: <ACCESS KEY>
    secretAccessKey: <SECRET KEY>
    • region: specifies the region where S3 is located.
    • bucket: specifies the bucket name of S3.
    • accessKeyId: specifies the Access Key of AWS.
    • secretAccessKey: specifies the Secret Key of AWS.
    • storageProvider:specifies the object storage provider, which is S3 in this case.
note
  • For KubeBlocks v0.8.0, the available storageProvider options are s3, cos, gcs-s3comp, obs, oss, minio, pvc, ftp, and nfs.
  • For different storageProvider, the configuration may differ. config and secrets in the above example are applied to S3.
  • Execute the command kubectl get storageproviders.storage.kubeblocks.io to view the supported storageProvider options.
  1. Specify the configuration file when installing KubeBlocks.

    kbcli kubeblocks install -f backuprepo.yaml

    Use the command below to check the BackupRepo after installation.

    kbcli backuprepo list

Manual BackupRepo configuration

If you do not configure the BackupRepo information when installing KubeBlocks, you can manually configure it by the following instructions.

  1. Install the S3 CSI driver (only used in the Mount method).

    # Enable the CSI-S3 add-on
    kbcli addon enable csi-s3

    # You can add flags to customize the installation of this add-on
    # CSI-S3 installs a daemonSet Pod on all nodes by default and you can set tolerations to install it on the specified node
    kbcli addon enable csi-s3 \
    --tolerations '[{"key":"taintkey","operator":"Equal","effect":"NoSchedule","value":"true"}]' \
    --tolerations 'daemonset:[{"key":"taintkey","operator":"Equal","effect":"NoSchedule","value":"true"}]'

    # View the status of CSI-S3 driver and make sure it is Enabled
    kbcli addon list csi-s3
  2. Create BackupRepo.

    kbcli backuprepo create my-repo \
    --provider s3 \
    --region cn-northwest-1 \
    --bucket test-kb-backup \
    --access-key-id <ACCESS KEY> \
    --secret-access-key <SECRET KEY> \
    --access-method Tool \ # Mount is also acceptable
    --default

    The above command creates a default backup repository my-repo.

    • my-repo is the name of the created backup repository. If you do not specify a name, the system creates a random name, following the format backuprepo-xxxxx.

    • --default means that this repository is set as the default repository. Note that there can only be one default global repository. If there exist multiple default repositories, KubeBlocks cannot decide which one to use (similar to the default StorageClass of Kubernetes), which further results in backup failure. Using kbcli to create BackupRepo can avoid such problems because kbcli checks whether there is another default repository before creating a new one.

    • --provider specifies the storage type, i.e. storageProvider, and is required for creating a BakcupRepo. The available values are s3, cos, gcs-s3comp, obs, oss, minio, ftp, and nas. Parameters for different storage providers vary and you can run kbcli backuprepo create --provider STORAGE-PROVIDER-NAME -h to view the flags for different storage providers. Please note that --provider is mandatory in configuration.

      After kbcli backuprepo create is executed successfully, the system creates the K8s resource whose type is BackupRepo. You can modify the annotation of this resource to adjust the default repository.

      # Cancel the default repository
      kubectl annotate backuprepo old-default-repo \
      --overwrite=true \
      dataprotection.kubeblocks.io/is-default-repo=false
      # Set a new default repository
      kubectl annotate backuprepo backuprepo-4qms6 \
      --overwrite=true \
      dataprotection.kubeblocks.io/is-default-repo=true
  3. View the BackupRepo and its status. If the status is Ready, the BackupRepo is ready.

    kbcli backuprepo list