mongodb-k8s

Charmed Operator for MongoDB

Channel Revision Published Runs on
6/stable 81 20 Aug 2025
Ubuntu 22.04
6/candidate 81 20 Aug 2025
Ubuntu 22.04
6/beta 81 20 Aug 2025
Ubuntu 22.04
6/edge 81 20 Aug 2025
Ubuntu 22.04
8-transition/edge 78 15 Aug 2025
Ubuntu 24.04
8/candidate 80 07 Aug 2025
Ubuntu 24.04
8/beta 80 07 Aug 2025
Ubuntu 24.04
8/edge 80 06 Aug 2025
Ubuntu 24.04
5/edge 39 14 Dec 2023
Ubuntu 22.04
juju deploy mongodb-k8s --channel 6/stable --trust
Show information

Platform:

Charmed MongoDB Tutorials > Deploy a sharded cluster > 2. Deploy MongoDB

Deploy MongoDB

Sharding is MongoDB’s solution to horizontal scaling. MongoDB’s documentation describes horizontal scaling in databases as the process of “ dividing a large database into smaller, more manageable pieces (called shards) and then distributing the shards across multiple machines.”

In Charmed MongoDB K8s, we create sharded clusters by deploying several MongoDB applications as individual cluster components, and then integrating them. This part of the tutorial will guide you through a practical example of a sharded cluster deployment.

Summary


Deploy cluster components

The first step to creating your sharded cluster is to deploy cluster components.

If you run juju deploy mongodb-k8s without specifying a role, the application will be automatically deployed as a replica set. To deploy a sharded cluster, we must manually define the roles of the individual cluster components:

juju deploy mongodb-k8s --config role="config-server" config-server
juju deploy mongodb-k8s --config role="shard" shard0
juju deploy mongodb-k8s --config role="shard" shard1

For a deeper explanation about the difference between replication and sharding see Explanation | Replication vs. sharded cluster deployments.

Use juju status --watch 1s to wait until these components are ready.

When the components are ready, your output should look similar to the example below:

Model           Controller  Cloud/Region         Version  SLA          Timestamp
tutorial        overlord    microk8s/localhost   3.1.7    unsupported  19:06:51+01:00

App            Version  Status   Scale  Charm    Channel    Rev  Exposed  Message    
config-server           blocked      1  mongodb  6/stable   158  no       Missing relation to shard(s). 
shard0                  blocked      1  mongodb  6/stable   158  no       Missing relation to config-server.
shard1                  blocked      1  mongodb  6/stable   158  no       Missing relation to config-server.

Unit              Workload  Agent    Address        Ports    Message    
config-server/0*  blocked   idle     10.56.148.138           Missing relation to shard(s).      
shard0/0*         blocked   idle     10.56.148.149           Missing relation to config-server.
shard1/0*         blocked   idle     10.56.148.60            Missing relation to config-server.   

All statuses are blocked because the shards are not yet integrated/related with the config-server.

Integrate shards with the config server

Juju integrations are a way to connect applications such that they can communicate with one another through compatible endpoints.

To integrate the shards with the config server, run

juju integrate config-server:config-server shard0:sharding
juju integrate config-server:config-server shard1:sharding
You’ll know your cluster is active and ready when juju status --watch 1s shows all apps as active.
Model           Controller  Cloud/Region         Version  SLA          Timestamp
tutorial        overlord    microk8s/localhost   3.1.7    unsupported  19:15:36+01:00

App            Version  Status  Scale  Charm    Channel  Rev  Exposed  Message     
config-server           active      1  mongodb  6/stable 158  no                                            
shard0                  active      1  mongodb  6/stable 158  no                                  
shard1                  active      1  mongodb  6/stable 158  no                                  

Unit              Workload  Agent    Address        Ports    Message    
config-server/0*  blocked   idle     10.56.148.138           Primary   
shard0/0*         blocked   idle     10.56.148.149           Primary
shard1/0*         blocked   idle     10.56.148.60            Primary                            

Next step: 3. Access a sharded cluster