KubeBlocks
BlogsEnterprise
⌘K
​
Overview
Quickstart

Topologies

MongoDB ReplicaSet Cluster
MongoDB Sharding Cluster

Operations

Lifecycle Management
Vertical Scaling
Horizontal Scaling
Volume Expansion
Manage MongoDB Services
Modify MongoDB Parameters
MongoDB Switchover
Decommission MongoDB Replica

Custom Secret

Custom Password

tpl

  1. Prerequisites
  2. Deploying the MongoDB ReplicaSet Cluster
  3. Verifying the Deployment
    1. Check the Cluster Status
    2. Verify Component and Pod Status
  4. Cleanup

Deploying a MongoDB ReplicaSet Cluster with KubeBlocks

A ReplicaSet provides high availability with one primary and multiple secondary replicas. Data is replicated asynchronously from the primary to the secondaries.

Prerequisites

    Before proceeding, ensure the following:

    • Environment Setup:
      • A Kubernetes cluster is up and running.
      • The kubectl CLI tool is configured to communicate with your cluster.
      • KubeBlocks CLI and KubeBlocks Operator are installed. Follow the installation instructions here.
    • Namespace Preparation: To keep resources isolated, create a dedicated namespace for this tutorial:
    kubectl create ns demo namespace/demo created

    Deploying the MongoDB ReplicaSet Cluster

    KubeBlocks uses a declarative approach for managing MongoDB Replication Clusters. Below is an example configuration for deploying a MongoDB ReplicaSet Cluster with one primary replica and two secondary replicas.

    Apply the following YAML configuration to deploy the cluster:

    apiVersion: apps.kubeblocks.io/v1 kind: Cluster metadata: name: mongodb-replicaset namespace: demo spec: terminationPolicy: Delete clusterDef: mongodb topology: replicaset componentSpecs: - name: mongodb serviceVersion: 6.0.27 replicas: 3 disableExporter: false resources: limits: cpu: "0.5" memory: "0.5Gi" requests: cpu: "0.5" memory: "0.5Gi" volumeClaimTemplates: - name: data spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi

    Key Configuration Details:

    • clusterDef: mongodb: Specifies the ClusterDefinition CR for the cluster.
    • topology: replicaset: Configures the cluster to use replicaset topology.
    • componentSpecs: Defines the components in the cluster

    Verifying the Deployment

    Check the Cluster Status

    Once the cluster is deployed, check its status:

    kubectl get cluster mongodb-replicaset -n demo -w

    Example Output:

    NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE mongodb-replicaset mongodb Delete Creating 40s mongodb-replicaset mongodb Delete Creating 71s mongodb-replicaset mongodb Delete Creating 71s mongodb-replicaset mongodb Delete Updating 71s mongodb-replicaset mongodb Delete Running 2m55s

    Verify Component and Pod Status

    kubectl get component -n demo -l app.kubernetes.io/instance=mongodb-replicaset kubectl get pod -n demo -l app.kubernetes.io/instance=mongodb-replicaset -L kubeblocks.io/role

    Example Output:

    NAME DEFINITION SERVICE-VERSION STATUS AGE mongodb-replicaset-mongodb mongodb-replicaset-1.0.0 6.0.27 Running 3m5s NAME READY STATUS RESTARTS AGE NAME READY STATUS RESTARTS AGE ROLE mongodb-replicaset-mongodb-0 4/4 Running 0 3m7s primary mongodb-replicaset-mongodb-1 4/4 Running 0 2m13s secondary mongodb-replicaset-mongodb-2 4/4 Running 0 119s secondary

    Cleanup

    To remove all resources created during this tutorial:

    kubectl delete cluster mongodb-replicaset -n demo kubectl delete ns demo

    © 2026 KUBEBLOCKS INC