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 our team. We will be in touch shortly.Close

How to scale replicas and shards

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

Summary


Scale a replica set

To scale a replica set, simply 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 --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 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

Last updated 5 months ago. Help improve this document in the forum.