Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

How to deploy MongoDB K8s

This is a guide on how to deploy Charmed MongoDB K8s 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 K8s.

Deploy a single replica

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

juju deploy mongodb-k8s --trust

The --trust flag is necessary to grant the application access to the Kubernetes cluster.

Deploy multiple replicas

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

juju deploy mongodb-k8s -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-k8s --config role="config-server" <config_server_name>
juju deploy mongodb-k8s --config role="shard" <shard_name_0>
juju deploy mongodb-k8s --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-k8s --config role="shard" <shard_name> -n 3
juju deploy mongodb-k8s --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 Scale replicas and shards > How to 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

Last updated a month ago. Help improve this document in the forum.