mongodb

MongoDB

Channel Revision Published Runs on
6/stable 199 04 Oct 2024
Ubuntu 22.04
6/candidate 199 04 Oct 2024
Ubuntu 22.04
6/beta 199 04 Oct 2024
Ubuntu 22.04
6/edge 210 12 Feb 2025
Ubuntu 22.04
5/stable 117 20 Apr 2023
Ubuntu 22.04
5/candidate 117 20 Apr 2023
Ubuntu 22.04
5/edge 139 21 Nov 2023
Ubuntu 22.04 Ubuntu 20.04
5/edge 109 06 Mar 2023
Ubuntu 22.04 Ubuntu 20.04
3.6/stable 100 28 Apr 2023
Ubuntu 20.04 Ubuntu 18.04
3.6/candidate 100 13 Apr 2023
Ubuntu 20.04 Ubuntu 18.04
3.6/edge 100 03 Feb 2023
Ubuntu 20.04 Ubuntu 18.04
juju deploy mongodb --channel 6/stable
Show information

Platform:

Ubuntu
22.04 20.04 18.04

How to deploy Charmed MongoDB

This is a guide on how to deploy Charmed MongoDB as a replica set or a sharded cluster.

Summary


Create a MongoDB replica set

You can create one or multiple replicas at once when deploying MongoDB.

Deploy a single replica

To deploy a single unit of MongoDB as a replica set, run:

juju deploy mongodb

This will deploy the latest stable release . To specify a different version, use the --channel flag, e.g. --channel=6/beta.

Deploy multiple replicas

To deploy MongoDB with multiple replicas, specify the number of desired replicas with the -n option:

juju deploy mongodb -n <number_of_replicas>

Create a MongoDB sharded cluster

To create a sharded cluster, we must first deploy each cluster component separately with a manually defined role, then integrate them.

Deploy cluster components with a single replica

Deploying a shard application will assign it one replica by default.

To deploy a sharded cluster with two shards, run:

juju deploy mongodb --config role="config-server" <config_server_name>
juju deploy mongodb --config role="shard" <shard_name_0>
juju deploy mongodb --config role="shard" <shard_name_1>

This will deploy the latest stable release . To specify a different version, use the --channel flag, e.g. --channel=6/beta.

Deploy cluster components with multiple replicas

To configure the amount of replicas for a shard or config-server during deployment, just use the -n flag.

To deploy a shard and config-server with 3 replicas each, run:

juju deploy mongodb --config role="shard" <shard_name> -n 3
juju deploy mongodb --config role="config-server" <config_server_name> -n 3

This will deploy the latest stable release . To specify a different version, use the --channel flag, e.g. --channel=6/beta.

Note that you can also change the number of replicas for a shard or config server after deployment. See How to scale > Add shards to a cluster.

Integrate cluster components

To create a cluster, integrate the shard applications with the config-server application.

For the case of two shards and one config server, you would run:

juju integrate config-server:config-server <shard_name_0>:sharding
juju integrate config-server:config-server <shard_name_1>:sharding

Deploy with Terraform

Make sure you have a working Terraform 1.8+ installed in your machine. You can install Terraform or OpenTofu via a snap.

Terraform modules make use of the Terraform Juju provider. More information about the Juju provider can be found here. For more information about Terraform, please refer to the official docs.

Charmed MongoDB has a base module that bundles all the base resources of the Charmed MongoDB solution. But it also provides two product modules that bundle all the resources and integrations for replica set deployments and sharded deployments. These deployments also integrate with necessary applications for: backups (s3-integrator), client connections (data-integrator), monitoring (grafana-agent), encryption (self-signed-certificates), and in the case of a sharded cluster a mongos router.

Deploy a replica set with terraform

Get access to the replica set product terraform module code:

git clone https://github.com/canonical/mongodb-operator.git
cd terraform/modules/replica_set

Then deploy Charmed MongoDB using the stand Terraform commands:

terraform init
terraform plan -out myfile
terraform apply "myfile"

Then you can watch and wait for your replica set to become available.

Deploy a sharded cluster with terraform

Get access to the shareded cluster product terraform module code:

git clone https://github.com/canonical/mongodb-operator.git
cd terraform/modules/sharded_cluster

Then deploy Charmed MongoDB using the stand Terraform commands:

terraform init
terraform plan -out myfile
terraform apply "myfile"

Then you can watch and wait for your shareded cluster to become available.