github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/kubeblocks-for-mongodb/cluster-management/scale-for-apecloud-mongodb.md (about)

     1  ---
     2  title: Scale for MongoDB cluster
     3  description: How to vertically scale a MongoDB cluster
     4  keywords: [mongodb, vertical sclaing, vertially scale a mongodb cluster]
     5  sidebar_position: 2
     6  sidebar_label: Scale
     7  ---
     8  
     9  # Scale for a MongoDB cluster
    10  
    11  For MongoDB, vertical scaling is supported.
    12  
    13  ## Vertical scaling
    14  
    15  You can vertically scale a cluster by changing resource requirements and limits (CPU and storage). For example, if you need to change the resource demand from 1C2G to 2C4G, vertical scaling is what you need.
    16  
    17  :::note
    18  
    19  During the vertical scaling process, a restart is triggered and the primary pod may change after the restarting.
    20  
    21  :::
    22  
    23  ### Before you start
    24  
    25  Check whether the cluster status is `Running`. Otherwise, the following operations may fail.
    26  
    27  ```bash
    28  kbcli cluster list mongodb-cluster
    29  ```
    30  
    31  ### Steps
    32  
    33  1. Change configuration. There are 3 ways to apply vertical scaling.
    34  
    35     **Option 1.** (**Recommended**) Use kbcli
    36  
    37     1. Use `kbcli cluster vscale` and configure the resources required.
    38  
    39        ***Example***
    40  
    41        ```bash
    42        kbcli cluster vscale mongodb-cluster --components=mongodb --cpu=500m --memory=500Mi
    43        >
    44        OpsRequest mongodb-cluster-verticalscaling-thglk created successfully, you can view the progress:
    45               kbcli cluster describe-ops mongodb-cluster-verticalscaling-thglk -n default
    46        ```
    47  
    48     - `--components` describes the component name ready for vertical scaling.
    49     - `--memory` describes the requested and limited size of the component memory.
    50     - `--cpu` describes the requested and limited size of the component CPU.
    51  
    52     2. Validate the scaling with `kbcli cluster describe-ops mongodb-cluster-verticalscaling-thglk -n default`.
    53  
    54       :::note
    55  
    56       `thglk` is the OpsRequest number randomly generated in step 1.
    57  
    58       :::
    59    
    60     **Option 2.** Change the YAML file of the cluster
    61  
    62     Change the configuration of `spec.components.resources` in the YAML file. `spec.components.resources` controls the requirement and limit of resources and changing them triggers a vertical scaling.
    63  
    64     ***Example***
    65  
    66     ```YAML
    67     apiVersion: apps.kubeblocks.io/v1alpha1
    68     kind: Cluster
    69     metadata:
    70       name: mongodb-cluster
    71       namespace: default
    72     spec:
    73       clusterDefinitionRef: mongodb
    74       clusterVersionRef: mongodb-5.0
    75       componentSpecs:
    76       - name: mongodb
    77         componentDefRef: mongodb
    78         replicas: 1
    79         resources: # Change the values of resources.
    80           requests:
    81             memory: "2Gi"
    82             cpu: "1000m"
    83           limits:
    84             memory: "4Gi"
    85             cpu: "2000m"
    86         volumeClaimTemplates:
    87         - name: data
    88           spec:
    89             accessModes:
    90               - ReadWriteOnce
    91             resources:
    92               requests:
    93                 storage: 1Gi
    94       terminationPolicy: Halt
    95     ```
    96  
    97  2. Validate the vertical scaling.
    98  
    99      ```bash
   100      kbcli cluster list mongodb-cluster
   101      >
   102      NAME              NAMESPACE   CLUSTER-DEFINITION   VERSION          TERMINATION-POLICY   STATUS    CREATED-TIME                 
   103      mongodb-cluster   default     mongodb              mongodb-5.0   WipeOut              Running   Apr 26,2023 11:50 UTC+0800  
   104      ```
   105  
   106     - STATUS=VerticalScaling: it means the vertical scaling is in progress.
   107     - STATUS=Running: it means the vertical scaling operation has been applied.
   108     - STATUS=Abnormal: it means the vertical scaling is abnormal. The reason may be the normal instances number is less than the total instance number or the leader instance is running properly while others are abnormal.
   109  
   110    :::note
   111  
   112    To solve the problem, you can check manually to see whether resources are sufficient. If AutoScaling is supported, the system recovers when there are enough resources, otherwise, you can create enough resources and check the result with kubectl describe command.
   113    
   114    :::
   115  
   116  :::note
   117  
   118  Vertical scaling does not synchronize parameters related to CPU and memory and it is required to manually call the opsRequest of configuration to change parameters accordingly. Refer to [Configuration](./../configuration/configuration.md) for instructions.
   119  
   120  :::
   121  
   122  3. Check whether the corresponding resources change.
   123  
   124      ```bash
   125      kbcli cluster describe mongodb-cluster
   126      ```