MongoDB


MongoDBMongoDB is a general-purpose document database. I've deployed my instance with a primary and a single replica. We'll use the Bitnami Helm chart as our installation.

The Bitnami Helm chart allows for a creation of a automatic backup job. Check out more information about backing up MongoDB in Kubernetes for how I've done this with the Bitnami chart.

Installation

As with many complex Helm charts, I like to grab the values.yaml file to adjust the deployment settings. We can do that with the following commands:

helm show values oci://registry-1.docker.io/bitnamicharts/mongodb > values.yaml

Now we can start editing the file to our needs. Below is some examples where I have customized the settings. For example, I use Longhorn for block storage. You will obviously need to adjust to your needs.

values.yaml

global:
...
  storageClass: "longhorn"
...
architecture: replicaset
...
auth:
  ## @param auth.enabled Enable authentication
  ## ref: https://docs.mongodb.com/manual/tutorial/enable-authentication/
  ##
  enabled: true
  ## @param auth.rootUser MongoDB(®) root user
  ##
  rootUser: root
  ## @param auth.rootPassword MongoDB(®) root password
  ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mongodb#setting-the-root-user-and-password-on-first-run
  ##
  rootPassword: "YourSuperSecretPassword"
  ## MongoDB(®) custom users and databases
  ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mongodb#creating-a-user-and-database-on-first-run
  ## @param auth.usernames List of custom users to be created during the initialization
  ## @param auth.passwords List of passwords for the custom users set at `auth.usernames`
  ## @param auth.databases List of custom databases to be created during the initialization
  ##
  usernames: [user1]
  passwords: [password1]
  databases: [db1]
  ...
  replicaSetKey: "MakeARandomStringForThis"
 ...
architecture: replication
...
arbiter:
  ## @param arbiter.enabled Enable deploying the arbiter
  ##   https://docs.mongodb.com/manual/tutorial/add-replica-set-arbiter/
  ##
  enabled: true
...

You can adjust the resources or resourcesPresets in the chart for your needs. If you only have a couple of databases, the default "small" should work for you. You can also choose to enable Prometheus metrics as well.

Deploy the Chart

Now that we've adjusted our values.yaml file we can deploy the chart. I like to keep these as bash scripts so I can easily redeploy the chart as I make configuration changes

build-mongodb.sh

#!/bin/bash

helm upgrade --install --namespace database \
             mongo oci://registry-1.docker.io/bitnamicharts/mongodb \
             -f values.yaml