Table of Contents

Install MongoDB in a cluster

Products: FastReport Corporate Server

Open-source data storage

This page describes the MongoDB installation option. An alternative is FerretDB - open-source alternative that uses PostgreSQL as a database engine. Instructions for installing using FerretDB can be found at link.

Start of installation

Add a repository for helm:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

The report server uses MongoDB to store report templates, prepared reports, and various documents exported from prepared reports.

Prepare the namespaces:

NAMESPACE=mongo
MONGO_USER=any_name
MONGO_PASS=mongo_password
MONGO_DB_SIZE=10Gi
MONGO_SERVICE_NAME=fr-mongo
kubectl create namespace $NAMESPACE

Note of the MONGO_SERVICE_NAME variable¾this name will be used to access MongoDB from the report server in the future.

Further configuration will differ depending on whether cloud provider storage or local storage is used. Below are two examples. Use only one of them, or modify the settings for your cloud provider.

Configure storage for the Hetzner cloud provider

helm install $MONGO_SERVICE_NAME bitnami/mongodb \
  --namespace $NAMESPACE \
  --set persistence.enabled=true \
  --set persistence.storageClass=hcloud-volumes \
  --set persistence.size=$MONGO_DB_SIZE
  --set auth.username=$MONGO_USER \
  --set auth.password=$MONGO_PASS \
  |  tee MongoDB.txt

Configure local storage

StorageClass provides a means for administrators to describe the storage “classes” they provide.

MONGO_DATA_DIR=/devkube/mongodb
MONGO_DB=reports_db # Any name can be used

##
## Create StorageClass for MongoDB
##
cat <<EOF | kubectl apply -n $NAMESPACE -f -
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-sc-mongodb
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
EOF

##
## Create Persistent volume for MongoDB
##

cat <<EOF | kubectl apply -n $NAMESPACE -f -
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongo-storage
  namespace: $NAMESPACE
  labels:
    type: local
spec:
  capacity:
    storage: $MONGO_DB_SIZE
  accessModes:
    - ReadWriteOnce
  storageClassName: local-sc-mongodb
  local:
    path: $MONGO_DATA_DIR
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - debian-10-2
EOF

To install MongoDB, use the following script:

  helm install $MONGO_SERVICE_NAME bitnami/mongodb \
      --namespace $NAMESPACE \
      --set persistence.storageClass=local-sc-mongodb \
      --set auth.username=$MONGO_USER \
      --set auth.password=$MONGO_PASS \
      --set auth.database=$MONGO_DB | tee MongoDB.txt

The result of running this script, in addition to installing MongoDB in the cluster, will be a file containing information about the result of the database installation. Note, that the parameters passed to the script were described at the very beginning of this document.

The easiest way to verify the correctness of MongoDB installation is to use Kubernetes Dashboard, the installation of which was described earlier.