Navigation
This version of the documentation is archived and no longer supported. To learn how to upgrade your version of MongoDB Kubernetes Operator, refer to the upgrade documentation.

Scale a Deployment

On this page

You can scale your replica set and sharded cluster deployments up or down to match your desired configuration. Scaling up increases the number of members and/or shards in the deployment, thereby improving your deployment’s redundancy and availability. The scale of your deployment is configured in its corresponding Custom Resource.

Scale a Replica Set
To scale your replica set deployment, set the spec.members setting to the desired number of replica set members. To learn more about replication, see Replication in the MongoDB manual.
Scale a Sharded Cluster

To scale your sharded cluster deployment, set the following settings as desired:

Setting Description
spec.shardCount Number of shards in the sharded cluster.
spec.mongodsPerShardCount Number of members per shard.
spec.mongosCount Number of Shard Routers.
spec.configServerCount Number of members in the Config Server.

To learn more about sharded cluster configurations, see Sharded Cluster Components in the MongoDB manual.

Considerations

The Kubernetes Operator does not support modifying deployment types. For example, you cannot convert a standalone deployment to a replica set. To modify the type of a deployment, we recommend the following procedure:

  1. Create the new deployment with the desired configuration.
  2. Back up the data from your current deployment.
  3. Restore the data from your current deployment to the new deployment.
  4. Test your application connections to the new deployment as needed.
  5. Once you have verified that the new deployment contains the required data and can be reached by your application(s), bring down the old deployment.

Examples

Select the desired tab based on the deployment configuration you want to scale:

Consider a replica set resource with the following Custom Resource:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
  name: <my-replica-set>
spec:
  members: 3
  version: 4.2.2-ent
  opsManager:
    configMapRef:
      name: <configMap.metadata.name>
            # Must match metadata.name in ConfigMap file
  credentials: <mycredentials>
  type: ReplicaSet
  persistent: true
...

To scale up this replica set and add more members:

  1. Adjust the spec.members setting to the desired number of members:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    ---
    apiVersion: mongodb.com/v1
    kind: MongoDB
    metadata:
      name: <my-secure-replica-set>
    spec:
      members: 4
      version: 4.2.2-ent
      opsManager:
        configMapRef:
          name: <configMap.metadata.name>
      credentials: <mycredentials>
      type: ReplicaSet
      persistent: true
    ...
    
  2. Reapply the configuration to Kubernetes:

    kubectl apply -f <repl-set-config>.yaml
    

Consider a sharded cluster resource with the following Custom Resource:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
  name: <my-sharded-cluster>
spec:
  shardCount: 2
  mongodsPerShardCount: 3
  mongosCount: 2
  configServerCount: 3
  version: 4.2.2-ent
  opsManager:
    configMapRef:
      name: <configMap.metadata.name>
            # Must match metadata.name in ConfigMap file
  credentials: <mycredentials>
  type: ShardedCluster
  persistent: true
...

To scale up this sharded cluster:

  1. Adjust the following settings to the desired values:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    ---
    apiVersion: mongodb.com/v1
    kind: MongoDB
    metadata:
      name: <my-secure-sharded-cluster>
    spec:
      shardCount: 3
      mongodsPerShardCount: 3
      mongosCount: 3
      configServerCount: 4
      version: 4.2.2-ent
      opsManager:
        configMapRef:
          name: <configMap.metadata.name>
      credentials: <mycredentials>
      type: ShardedCluster
      persistent: true
    ...
    
  2. Reapply the configuration to Kubernetes:

    kubectl apply -f <sharded-cluster-config>.yaml