You are looking at the documentation of a prior release. To read the documentation of the latest release, please visit here.

New to KubeDB? Please start here.

MongoDB Vertical Scaling

This guide will give an overview on how KubeDB Ops-manager operator updates the resources(for example CPU and Memory etc.) of the MongoDB database.

Before You Begin

How Vertical Scaling Process Works

The following diagram shows how KubeDB Ops-manager operator updates the resources of the MongoDB database. Open the image in a new tab to see the enlarged version.

  Vertical scaling process of MongoDB
Fig: Vertical scaling process of MongoDB

The vertical scaling process consists of the following steps:

  1. At first, a user creates a MongoDB Custom Resource (CR).

  2. KubeDB Provisioner operator watches the MongoDB CR.

  3. When the operator finds a MongoDB CR, it creates required number of PetSets and related necessary stuff like secrets, services, etc.

  4. Then, in order to update the resources(for example CPU, Memory etc.) of the MongoDB database the user creates a MongoDBOpsRequest CR with desired information.

  5. KubeDB Ops-manager operator watches the MongoDBOpsRequest CR.

  6. When it finds a MongoDBOpsRequest CR, it halts the MongoDB object which is referred from the MongoDBOpsRequest. So, the KubeDB Provisioner operator doesn’t perform any operations on the MongoDB object during the vertical scaling process.

  7. Then the KubeDB Ops-manager operator will update resources of the PetSet Pods to reach desired state.

  8. After the successful update of the resources of the PetSet’s replica, the KubeDB Ops-manager operator updates the MongoDB object to reflect the updated state.

  9. After the successful update of the MongoDB resources, the KubeDB Ops-manager operator resumes the MongoDB object so that the KubeDB Provisioner operator resumes its usual operations.

Vertical Scaling Modes

KubeDB actuates vertical scaling in one of two modes, selected through the spec.verticalScaling.mode field of the MongoDBOpsRequest:

  • Restart (default): The operator patches the PetSet with the new resources and restarts the Pods (one at a time, honoring the database’s failover rules) so they come back with the updated CPU and Memory. This works on every Kubernetes cluster.
  • InPlace: The operator resizes the running containers in place using the Kubernetes in-place Pod resize (pods/resize subresource) — no Pod restart, so scaling happens without downtime or failover. If a Node cannot accommodate the new resources (the resize is reported Infeasible), the operator automatically falls back to the Restart behavior for that Pod.

If spec.verticalScaling.mode is omitted, it defaults to Restart.

Note: InPlace mode relies on the Kubernetes InPlacePodVerticalScaling feature gate, which is enabled by default from Kubernetes v1.33. On older clusters, or when the feature gate is disabled, use Restart mode.

In the next docs, we are going to show a step by step guide on updating resources of MongoDB database using MongoDBOpsRequest CRD.