Logical MongoDB BackupΒΆ

If it hasn't been done already, the bitnami Helm repository needs to be added to your local configuration:

# Add bitnami helm repo
$ helm repo add bitnami https://charts.bitnami.com/bitnami

Install the MongoDB chart from the bitnami Helm repository:

$ kubectl create namespace mongodb-logical
$ helm install mongo-logical bitnami/mongodb --namespace mongodb-logical \
    --set architecture="replicaset"

Note

We create two Blueprints here. Because the backup of the MongoDB is completed from the primary MongoDB pod itself, we will not have to do any backup related activities in the secondary MongoDB pods. We therefore create a noop Blueprint and annotate the secondary MongoDB StatefulSet to use the noop Blueprint.

To create a Blueprint resource, please run the command below:

$ kubectl --namespace kasten-io apply -f \
    https://raw.githubusercontent.com/kanisterio/kanister/0.58.0/examples/stable/mongodb/blueprint-v2/mongo-blueprint.yaml

To create another Blueprint resource, create a file named mongo_noop_logical.yaml with following contents:

apiVersion: cr.kanister.io/v1alpha1
kind: Blueprint
metadata:
  name: mongo-noop
actions:
  backup:
    type: StatefulSet
    phases:
    - func: KubeExec
      name: lockMongo
      args:
        namespace: "{{ .StatefulSet.Namespace }}"
        pod: "{{ index .StatefulSet.Pods 0 }}"
        container: mongodb-secondary
        command:
        - echo
        - NOOP

and then apply the Blueprint using the command below:

$ kubectl --namespace=kasten-io create -f mongo_noop_logical.yaml

Once the Blueprint is created, we will have to annotate the StatefulSets with the correct annotations to instruct K10 to use the Blueprint while performing operations on this MongoDB instance. We annotate the primary StatefulSet with the Blueprint named mongodb-logical, and annotate the secondary one with the Blueprint named mongo-noop to avoid taking any action on the secondary members.

$ kubectl annotate statefulset mongo-logical-mongodb-primary kanister.kasten.io/blueprint='mongodb-blueprint' \
      --namespace=mongodb-logical
$ kubectl annotate statefulset mongo-logical-mongodb-secondary kanister.kasten.io/blueprint='mongo-noop' \
      --namespace=mongodb-logical

Finally, use K10 to backup and restore the application.