Navigation

Deploy a Sharded Cluster

On this page

Sharded clusters provide horizontal scaling for large data sets and enable high throughput operations by distributing the data set across a group of servers.

To learn more about sharding, see Sharding Introduction in the MongoDB manual.

Use this procedure to deploy a new sharded cluster that Ops Manager manages. Later, you can use Ops Manager to add shards and perform other maintenance operations on the cluster.

Prerequisites

You must provision servers onto which to deploy, and Ops Manager must have access to the servers.

Important

If you will run MongoDB Enterprise and provision your own Linux servers, then you must manually install a set of dependencies to each server before installing MongoDB. The MongoDB manual provides the appropriate command to install the dependencies. See the link for the server’s operating system:

Added in Ops Manager 4.0

You can use Kubernetes to deploy MongoDB instances with Ops Manager version 4.0 or later.

Prerequisites

To deploy a standalone using a Kubernetes object, you need to meet the prerequisites for, and complete the procedures on, the Install Kubernetes Operator page.

Considerations

Unique Names for Sharded Clusters

Use unique names for the new cluster and its shards.

Important

Replica set, sharded cluster, and shard names within the same project must be unique. Failure to have unique names for the deployments will result in broken backup snapshots.

Do Not Deploy Monitoring Agents inside and outside Kubernetes

Do not mix MongoDB deployments outside Kubernetes with ones insider Kubernetes in the same Project.

Due to Kubernetes network translation, a Monitoring Agent outside Kubernetes cannot monitor MongoDB instnaces inside Kubernetes. For this reason, k8s and non-k8s deployments in the same Project is not supported. Use separate projects.

Configuration Server Deployment Architecture

New in version Ops: Manager 4.0

If you select MongoDB 3.2 or later for your configuration server mongod processes, Ops Manager deploys your configuration servers as a replica set. If you select MongoDB 3.0 or earlier for your configuration server mongod processes, Ops Manager deploys mirrored configuration servers.

To learn more about Config Server Replica Sets (CSRS) and mirrored configuration servers (SCCC), see Config Servers.

Procedure

1

Click Deployment.

2

Open the Cluster Creation View.

Click the Add New arrow in the top-right of the Deployment page. Select New Cluster from the drop-down menu to open the Create New Cluster view.

3

Configure Cluster-Wide Settings.

The Cluster Configuration section contains the following cluster-wide configuration settings. Settings marked with an * asterisk in the Ops Manager UI are required.

Setting Description
Cluster Name Specify the name of your sharded cluster deployment. You cannot change this once set.
Config Server Replica Set Name

Specify the name of your Config Server Replica Set. You cannot change this once set. This setting corresponds to the _id replica configuration option.

Ops Manager only displays this option if you selected MongoDB 3.2 or later as the Version of your configuration servers.

Shard Name Prefix Specify the prefix of each shard in the cluster. Ops Manager names each shard in the cluster using the <prefix_n> format, where n is a 0-indexed, monotonically increasing integer.
Process Name

Hostname and port of a mongod or mongos associated to the sharded cluster.

Ops Manager groups mongod processes under their parent replica set name, and mongos processes under mongoses. Ops Manager then groups all the cluster components under the cluster name. Click the caret right icon to the left of a grouping to list its sub-groups or processes. Modifying any of the available settings for a grouping changes the corresponding value in its sub-groups and processes.

Note

For clusters running MongoDB 3.0 or earlier, Ops Manager groups the config server mongod processes under configServers.

Version

Select the MongoDB server version of the mongod or mongos process.

If the dropdown menu does not include the MongoDB version you want for your deployment, you must enable it in the Version Manager.

Data Directory

Specify the directory where the mongod process stores data files. This setting corresponds to the storage.dbPath mongod configuration file option. The Ops Manager Automation Agent must have file system permission to read, write, and execute all files and folders in the specified directory.

Each mongod process must have its own database directory. If deploying multiple mongod processes on the same host, ensure each process has its own distinct directory.

Log File

Specify the full path to the mongod or mongos log file, including the log file name and extension. This setting corresponds to the systemLog.path configuration file option. The mongod or mongos must have permission to read and write to the specified file.

Example

Specifying /var/log/mongodb/mongo.log directs the mongod or mongos to store its logfile to /var/log/mongodb/ as mongo.log.

The mongod or mongos have its own unique log file. If deploying multiple mongod or mongos processes to the same host, ensure each mongod or mongos has its own distinct logfile.

4

Configure Each Shard in Your Cluster.

From the Member Configuration section, click Shard Settings to open the shard configuration options. Ops Manager lists each shard in the cluster and the mongod processes associated to that shard. Each shard process has the the following options:

Setting Description
Member

Select one of the following replica set member roles from the menu:

  • Default

    A data-bearing member of the replica set that can become the primary and vote in elections.

  • Arbiter

    A non-data bearing member of the replica set that can vote in elections. Corresponds to the arbiterOnly replica configuration option.

  • Hidden

    A data-bearing member of the replica set that can vote in elections. Corresponds to the hidden replica configuration option.

  • Delayed Hidden

    A data-bearing member of the replica set that can vote in elections. Corresponds to the slaveDelay and hidden replica configuration options.

Hostname Select from the menu the host to which Ops Manager Automation deploys the replica set member. The menu only lists hosts under Ops Manager Automation. For complete documentation on adding servers to Ops Manager Automation, see Provision Servers for Automation.
Port

Specify the IANA port number for the mongod process. This setting corresponds to the net.port configuration file option. Defaults to 27017.

The mongod must have exclusive access to the specified port. If deploying multiple mongod processes to a single host, you must select a unique unused port for each process.

Votes Specify the number of votes that the replica set member has during elections. This setting corresponds to the votes mongod replica set configuration option.
Priority Specify the priority of the member during elections. Replica set members with a priority of 0 cannot become the primary and cannot trigger elections. This setting corresponds to the priority mongod replica set configuration option.
Delay Specify the number of seconds “behind” the primary member this member should “lag”. This setting corresponds to the slaveDelay mongod replica set configuration option.
Build Indexes Specify true to direct the mongod to build indexes. This setting corresponds to the buildIndexes mongod replica set configuration option.
Tags

Specify the tag or tags associated to the replica set. This setting corresponds to the tags mongod replica set configuration option.

For complete documentation on replica set tags, see Replica Set Tags

Add a Mongod

Adds an additional mongod process as a replica set member.

Adding a new mongod process also updates the list of processes in the Cluster Configuration section. You must configure the Version, Data Directory, and Log File of the new process.

Click Add a Shard to add additional shards to the cluster. You must also configure the Version, Data Directory, and Log File of each mongod in the shard under the Cluster Configuration section.

5

Configure Each Configuration Server in Your Cluster.

Ops Manager displays a different heading for your configuration server settings depending on the MongoDB version you selected for your configuration servers.

MongoDB 3.2 or Later:

From the Member Configuration section, click Config Server Replica Set Settings to open the CSRS configuration options. Each config server replica set member has the following options:

Setting Description
Member

Select one of the following replica set member roles from the menu:

  • Default

    A data-bearing member of the replica set that can become the primary and vote in elections.

  • Arbiter

    A non-data bearing member of the replica set that can vote in elections. Corresponds to the arbiterOnly replica configuration option.

  • Hidden

    A data-bearing member of the replica set that can vote in elections. Corresponds to the hidden replica configuration option.

  • Delayed Hidden

    A data-bearing member of the replica set that can vote in elections. Corresponds to the slaveDelay and hidden replica configuration options.

Hostname Select from the menu the host to which Ops Manager Automation deploys the replica set member. The menu only lists hosts under Ops Manager Automation. For complete documentation on adding servers to Ops Manager Automation, see Provision Servers for Automation.
Port

Specify the IANA port number for the mongod process. This setting corresponds to the net.port configuration file option. Defaults to 27017.

The mongod must have exclusive access to the specified port. If deploying multiple mongod processes to a single host, you must select a unique unused port for each process.

Votes Specify the number of votes that the replica set member has during elections. This setting corresponds to the votes mongod replica set configuration option.
Priority Specify the priority of the member during elections. Replica set members with a priority of 0 cannot become the primary and cannot trigger elections. This setting corresponds to the priority mongod replica set configuration option.
Delay Specify the number of seconds “behind” the primary member this member should “lag”. This setting corresponds to the slaveDelay mongod replica set configuration option.
Build Indexes Specify true to direct the mongod to build indexes. This setting corresponds to the buildIndexes mongod replica set configuration option.
Tags

Specify the tag or tags associated to the replica set. This setting corresponds to the tags mongod replica set configuration option.

For complete documentation on replica set tags, see Replica Set Tags

Add a Mongod

Adds an additional mongod process as a replica set member.

Adding a new mongod process also updates the list of processes in the Cluster Configuration section. You must configure the Version, Data Directory, and Log File of the new process.

MongoDB 3.0 or Earlier

From the Member Configuration section, click Config Server Settings to open the configuration server options. Each configuration server has the following options:

Setting Description
Hostname Select from the menu the host to which Ops Manager Automation deploys the replica set member. The menu only lists hosts under Ops Manager Automation. For complete documentation on adding servers to Ops Manager Automation, see Provision Servers for Automation.
Port

Specify the IANA port number for the mongod process. This setting corresponds to the net.port configuration file option. Defaults to 27017.

The mongod must have exclusive access to the specified port. If deploying multiple mongod processes to a single host, you must select a unique unused port for each process.

6

Configure Each mongos in Your Cluster.

From the Member Configuration section, click Mongos Settings to open the mongos configuration options. Each mongos process has the following options:

Setting Description
Hostname Select from the menu the host to which Ops Manager Automation deploys the mongos. The menu only lists hosts under Ops Manager Automation. For complete documentation on adding servers to Ops Manager Automation, see Provision Servers for Automation.
Port

Specify the IANA port number for the mongos process. This setting corresponds to the net.port configuration file option. Defaults to 27017.

The mongos must have exclusive access to the specified port. If deploying multiple mongos processes to a single host, you must select a unique unused port for each process.

Add a Mongos Click to add an additional mongos process.
7

Configure Each Replica Set in your Cluster.

The Replication Settings section contains the following configuration options for each replica set in the cluster:

Setting Description
Protocol Version

Select the replication protocol version used by the replica set. This setting corresponds to the protocolVersion replica set configuration option.

For more information, see Replica Set Protocol Versions.

Chaining Allowed Specify true to allow secondary members to replicate from other secondary members. This setting corresponds to the chainingAllowed replica set configuration option.
Write Concern Majority Journal Default Determines the behavior of {w:"majority"} write concern if the write concern does not explicitly specify the journal option j. This setting corresponds to the writeConcernMajorityJournalDefault replica set configuration option.
Heartbeat Timeout (secs) Specify the number of seconds that the replica set members wait for a successful heartbeat from each other. This setting corresponds to the heartbeatTimeoutSecs replica set configuration option.
Election Timeout (ms) Specify the time limit in milliseconds for detecting when a replica set’s primary is unreachable. This setting corresponds to the electionTimeoutMillis replica set configuration option.
CatchUp Timeout (ms) Specify the time limit in milliseconds for a newly elected primary to sync, or catch up, with the other replica set members that may have more recent writes. This setting corresponds to the catchUpTimeoutMillis replica set configuration option.
CatchUp Takeover Delay (ms) Specify the time in milliseconds a node waits to initiate a catchup takeover after determining it is ahead of the current primary. This setting corresponds to the catchUpTakeoverDelayMillis replica set configuration option.
8

Configure your Ops Manager managed indexes.

The Index Configuration section allows you to create, change, or remove Ops Manager managed indexes on your MongoDB deployment. For complete documentation on Ops Manager managed indexes, see Manage Indexes.

Setting Description
Add Adds an index for Ops Manager to manage. Select an index type to open the index creation walkthrough.
Unmanage Removes the index from Ops Manager management. Only visible if you have at least one Ops Manager managed index. Removing an index from Ops Manager management does not delete the index.
9

Set any advanced configuration options for your MongoDB sharded cluster.

The Advanced Options section allows you to set MongoDB runtime options for each MongoDB process in your deployment.

To add an option:

  1. Click Add Option.
  2. From the Select a Process Type menu, click the process for which you want to add an option.
  3. Click Select a Startup Option and select the configuration option.
  4. Ops Manager displays a context-sensitive input for configuring an acceptable value for the selected option.
  5. Click Add to add the selected option and its corresponding value to every process of the selected process type in the cluster.

Ops Manager lists each process in the cluster grouped logically. Click the grey arrow to the left of the logical grouping to display its sub-groupings and processes. You can modify the advanced options for each process individually as necessary.

For descriptions of the available Advanced Options, see Advanced Options for MongoDB Deployments.

10

Click Create Cluster.

Ops Manager redirects you to the Deployment view, where you must review the cluster configuration before Ops Manager begins deployment.

11

Click Review & Deploy to review your changes.

12

Review and approve your changes.

Ops Manager displays your proposed changes.

  1. If you are satisfied, click Confirm & Deploy.
  2. If you want to make further configuration changes, click Cancel. Click Modify for the cluster to make additional changes.
1

Copy the following example sharded cluster Kubernetes object specification.

This is a YAML file that you can modify to meet your desired configuration. The highlighted lines should be changed for your sharded cluster configuration.

---
apiVersion: mongodb.com/v1
kind: MongoDbShardedCluster
metadata:
  name: <myShardedCluster>
  namespace: <metadata.namespace> # Should match metadata.namespace in
                                  # your configmap file.
spec:
  shardCount: 2
  mongodsPerShardCount: 3
  mongosCount: 2
  configServerCount: 3
  version: 3.6.3
  persistent: false
  project: <myConfigMap> # Should match metadata.name in your
                         # configmap file.
  credentials: <myCredentials>

You will need to change the highlighted settings to match your desired sharded cluster deployment.

2

Open your preferred text editor and paste the object specification into a new text file.

3

Configure the settings highlighted in the preceeding step as follows.

Key Type Description Example
metadata.name string

Label for this Kubernetes sharded cluster object.

See also

my-project
metadata.namespace string

Scope of object names. Kubernetes namespace where this MongoDB Kubernetes resource and other objects are created.

This namespace must be the same one used for the ConfigMap but may be different than the one you used for your Kubernetes Operator. Using two different namespaces allows you to delete your sharded cluster or all of the resources in the namespace without affecting your Kubernetes Operator.

See also

mongodb
spec.shardCount integer Number of shards to deploy. 2
spec.mongodsPerShardCount integer Number of shard members per shard. 3
spec.mongosCount integer Number of shard routers to deploy. 2
spec.configServerCount integer Number of members of the config server replica set. 3
spec.version string

Version of MongoDB that this sharded cluster should run.

The format should be X.Y.Z for the Community edition and X.Y.Z-ent for the Enterprise edition.

To learn more about MongoDB versioning, see MongoDB Version Numbers in the MongoDB Manual.

3.6.5
spec.project string

Label for the Kubernetes object.

Note

This value must match the value you provided for metadata.name in your Ops Manager project ConfigMap.

myProject
spec.credentials string Name of the Kubernetes secret you created as Ops Manager API authentication credentials for the Kubernetes Operator to communicate with Ops Manager. myCredentials
spec.persistent string

Optional.

Flag indicating if this MongoDB Kubernetes resource should use persistent volumes for storage. Persistent volumes are not deleted when the MongoDB Kubernetes resource is stopped or restarted.

Note

If you do not use persistent volumes, the Disk Usage and Disk IOPS charts cannot be displayed in either the Processes tab on the Deployment page or in the Metrics page when reviewing the data for this deployment.

true
4

Add any additional accepted settings for a sharded cluster deployment.

You can also add any of the following optional settings to the object specification file for a sharded cluster deployment:

For config server

  • configSrvPodSpec.cpu
  • configSrvPodSpec.memory
  • configSrvPodSpec.storage
  • configSrvPodSpec.storageClass
  • configSrvPodSpec.podAntiAffinityTopologyKey
  • configSrvPodSpec.podAffinity

For shard routers

  • mongosPodSpec.cpu
  • mongosPodSpec.memory
  • mongosPodSpec.podAntiAffinityTopologyKey
  • mongosPodSpec.nodeAffinity

For shard members

  • shardPodSpec.cpu
  • shardPodSpec.memory
  • shardPodSpec.storage
  • shardPodSpec.storageClass
  • shardPodSpec.podAntiAffinityTopologyKey
5

Save this file with a .yaml file extension.

6

Start your sharded cluster deployment.

Invoke the following Kubernetes command to create your sharded cluster:

kubectl apply -f <sharded-cluster-conf>.yaml -n <metadata.namespace>

Check the log after running this command. If the creation was successful, you should see a message similar to the following:

2018-06-26T10:30:30.346Z INFO operator/shardedclusterkube.go:52 Created! {"sharded cluster": "my-sharded-cluster"}