Charmed Operator for MongoDB

Channel Revision Published Runs on
6/stable 61 15 Nov 2024
Ubuntu 22.04
6/candidate 61 15 Nov 2024
Ubuntu 22.04
6/beta 61 15 Nov 2024
Ubuntu 22.04
6/edge 61 15 Nov 2024
Ubuntu 22.04
5/edge 39 14 Dec 2023
Ubuntu 22.04
juju deploy mongodb-k8s --channel 6/stable
Show information

Platform:

How to scale replicas and shards

In this guide, you will find instructions on how to scale your MongoDB K8s replica set and sharded cluster.

Summary


Scale a replica set

To scale a replica set, use juju’s add-unit and remove-unit commands.

Add replicas

To add more replicas, run:

juju add-unit <application_name> -n <num_of_replicas_to_add>

Where an application can be either a bare replica set, shard, or config-server.

Remove replicas

remove-unit allows removing more than one replica so long as they do not constitute the majority of the replicas.

To remove replicas, run:

juju remove-unit <application_name>/<unit_number> <application_name>/<unit_number>

Where an application can be either a bare replica set, shard, or config-server.

Retrieve primary replica

To retrieve the primary replica, use the juju action get-primary:

juju run <application_name>/<unit_number> get-primary

Where an application can be either a bare replica set, shard, or config-server.

Scale a sharded cluster

Add shards to a cluster

To add a shard to a cluster, first deploy the new shard.

To deploy a shard named new-shard, run:

juju deploy mongodb-k8s --config role="shard" new-shard -n <number of replicas for shard>

Wait for the shard to show blocked and idle with juju status --watch 1s.

Next, add it to your config-server:

juju integrate <config-server-name>:config-server new-shard:sharding

Remove shards from a cluster

Like official MongoDB, Charmed MongoDB K8s does not support removing the last shard.

To remove a shard named new-shard that is not the last, run:

juju remove-relation <config-server-name>:config-server new-shard:sharding

You can watch your sharded cluster scale down with juju status --watch 1s.

Once the shard is drained, you can fully remove it with:

juju remove-application new-shard

Help improve this document in the forum (guidelines). Last updated 2 months ago.