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

     1  ---
     2  title: Scale for a Pulsar
     3  description: How to scale a Pulsar cluster, horizontal scaling, vertical scaling
     4  keywords: [mysql, horizontal scaling, vertical scaling]
     5  sidebar_position: 2
     6  sidebar_label: Scale
     7  ---
     8  
     9  # Scale for a Pulsar cluster
    10  
    11  ## Vertical scaling
    12  
    13  You can vertically scale a cluster by changing resource requirements and limits (CPU and storage). For example, if you need to change the resource class from 1C2G to 2C4G, vertical scaling is what you need.
    14  
    15  :::note
    16  
    17  During the vertical scaling process, all pods restart in the order of learner -> follower -> leader, and the leader pod may change after restarting.
    18  
    19  :::
    20  
    21  ### Before you start
    22  
    23  Check whether the cluster status is `Running`. Otherwise, the following operations may fail.
    24  
    25  ```bash
    26  kbcli cluster list pulsar
    27  ```
    28  
    29  ### Steps
    30  
    31  1. Change configuration. There are 3 ways to apply vertical scaling.
    32  
    33     **Option 1.** (**Recommended**) Use kbcli
    34  
    35     Configure the parameters `--components`, `--memory`, and `--cpu` and run the command.
    36  
    37     ```bash
    38     kbcli cluster vscale pulsar --cpu=3 --memory=10Gi --components=broker,bookies  
    39     ```
    40  
    41     - `--components` describes the component name ready for vertical scaling.
    42     - `--memory` describes the requested and limited size of the component memory.
    43     - `--cpu` describes the requested and limited size of the component CPU.
    44  
    45     **Option 2.** Create an OpsRequest
    46    
    47     Apply an OpsRequest to the specified cluster. Configure the parameters according to your needs.
    48  
    49     ```bash
    50     kubectl create -f -<< EOF
    51     apiVersion: apps.kubeblocks.io/v1alpha1
    52     kind: OpsRequest
    53     metadata:
    54       generateName: pulsar-vscale-
    55     spec:
    56       clusterRef: pulsar
    57       type: VerticalScaling
    58       verticalScaling:
    59       - componentName: broker
    60         requests:
    61           memory: "10Gi"
    62           cpu: 3
    63         limits:
    64           memory: "10Gi"
    65           cpu: 3
    66       - componentName: bookies
    67         requests:
    68           memory: "10Gi"
    69           cpu: 3
    70         limits:
    71           memory: "10Gi"
    72           cpu: 3      
    73     EOF
    74     ```
    75    
    76     **Option 3.** Edit Pulsar cluster with `kubectl`.
    77  
    78     ```bash
    79     kubectl edit cluster pulsar
    80     ```
    81  
    82  2. Check the cluster status to validate the vertical scaling.
    83  
    84      ```bash
    85      kbcli cluster list pulsar
    86      ```
    87  
    88     - STATUS=VerticalScaling: it means the vertical scaling is in progress.
    89     - STATUS=Running: it means the vertical scaling operation has been applied.
    90     - STATUS=Abnormal: it means the vertical scaling is abnormal. The reason may be that the number of the normal instances is less than that of the total instance or the leader instance is running properly while others are abnormal.
    91       > To solve the problem, you can manually check whether this error is caused by insufficient resources. Then if AutoScaling is supported by the Kubernetes cluster, the system recovers when there are enough resources. Otherwise, you can create enough resources and troubleshoot with `kubectl describe` command.
    92  
    93  :::note
    94  
    95  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.
    96  
    97  :::
    98  
    99  3. Check whether the corresponding resources change.
   100  
   101      ```bash
   102      kbcli cluster describe pulsar
   103      ```
   104  
   105  ## Horizontal scaling
   106  
   107  Horizontal scaling changes the amount of pods. For example, you can apply horizontal scaling to scale pods up from three to five. The scaling process includes the backup and restoration of data.
   108  
   109  ### Before you start
   110  
   111  - It is recommended to keep 3 nodes without scaling for Zookeeper, and other components can scale horizontally for multiple or single components
   112  - The scaling of the Bookies node needs to be cautious. The data copy is related to the EnsembleSize, Write Quorum, and Ack Quorum configurations, scaling may cause data loss. Check [Pulsar official document](https://pulsar.apahe.org/docs/3.0.x/administration-zk-bk/#decommission-bookies-cleanly) for detailed information.
   113  
   114  ### Steps
   115  
   116  1. Change configuration. There are 3 ways to apply horizontal scaling.
   117  
   118     **Option 1.** (**Recommended**) Use kbcli
   119  
   120     Configure the parameters `--components` and `--replicas`, and run the command.
   121  
   122     ```bash
   123     kbcli cluster hscale pulsar --replicas=5 --components=broker,bookies                  Running        Jan 29,2023 14:29 UTC+0800
   124     ```
   125  
   126     - `--components` describes the component name ready for horizontal scaling.
   127     - `--replicas` describes the replicas with the specified components.
   128  
   129     **Option 2.** Create an OpsRequest
   130  
   131     Apply an OpsRequest to a specified cluster. Configure the parameters according to your needs.
   132  
   133      ```bash
   134      kubectl create -f -<< EOF
   135      apiVersion: apps.kubeblocks.io/v1alpha1
   136      kind: OpsRequest
   137      metadata:
   138        generateName: pulsar-horizontalscaling-
   139      spec:
   140        clusterRef: pulsar
   141        type: HorizontalScaling  
   142        horizontalScaling:
   143        - componentName: broker
   144          replicas: 5
   145        - componentName: bookies
   146          replicas: 5
   147      EOF
   148      ```
   149  
   150     **Option 3.** Edit cluster with `kubectl`.
   151  
   152     ```bash
   153     kubectl edit cluster pulsar
   154     ```
   155    
   156  2. Validate the horizontal scaling operation.
   157  
   158     Check the cluster STATUS to identify the horizontal scaling status.
   159  
   160     ```bash
   161     kubectl get ops
   162     >
   163     NAME                             TYPE               CLUSTER   STATUS    PROGRESS   AGE
   164     pulsar-horizontalscaling-9lfvc   HorizontalScaling  pulsar    Succeed   3/3        8m49s
   165     ```
   166  
   167  3. Check whether the corresponding resources change.
   168  
   169     ```bash
   170     kbcli cluster describe mysql-cluster
   171     ```
   172  
   173  ### Handle the snapshot exception
   174  
   175  If `STATUS=ConditionsError` occurs during the horizontal scaling process, you can find the cause from `cluster.status.condition.message` for troubleshooting.
   176  In the example below, a snapshot exception occurs.
   177  
   178  ```bash
   179  Status:
   180    conditions: 
   181    - lastTransitionTime: "2023-02-08T04:20:26Z"
   182      message: VolumeSnapshot/mysql-cluster-mysql-scaling-dbqgp: Failed to set default snapshot
   183        class with error cannot find default snapshot class
   184      reason: ApplyResourcesFailed
   185      status: "False"
   186      type: ApplyResources
   187  ```
   188  
   189  ***Reason***
   190  
   191  This exception occurs because the `VolumeSnapshotClass` is not configured. This exception can be fixed after configuring `VolumeSnapshotClass`, but the horizontal scaling cannot continue to run. It is because the wrong backup (volumesnapshot is generated by backup) and volumesnapshot generated before still exist. Delete these two wrong resources and then KubeBlocks re-generates new resources.
   192  
   193  ***Steps:***
   194  
   195  1. Configure the VolumeSnapshotClass by running the command below.
   196  
   197     ```bash
   198     kubectl create -f - <<EOF
   199     apiVersion: snapshot.storage.k8s.io/v1
   200     kind: VolumeSnapshotClass
   201     metadata:
   202       name: csi-aws-vsc
   203       annotations:
   204         snapshot.storage.kubernetes.io/is-default-class: "true"
   205     driver: ebs.csi.aws.com
   206     deletionPolicy: Delete
   207     EOF
   208     ```
   209  
   210  2. Delete the wrong backup (volumesnapshot is generated by backup) and volumesnapshot resources.
   211  
   212     ```bash
   213     kubectl delete backup -l app.kubernetes.io/instance=mysql-cluster
   214     
   215     kubectl delete volumesnapshot -l app.kubernetes.io/instance=mysql-cluster
   216     ```
   217  
   218  ***Result***
   219  
   220  The horizontal scaling continues after backup and volumesnapshot are deleted and the cluster restores to running status.