github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/kubeblocks-for-redis/cluster-management/scale-for-a-redis-cluster.md (about) 1 --- 2 title: Scale for a Redis cluster 3 description: How to scale a Redis cluster, horizontal scaling, vertical scaling 4 keywords: [redis, horizontal scaling, vertical scaling, scale] 5 sidebar_position: 2 6 sidebar_label: Scale 7 --- 8 9 # Scale for a Redis cluster 10 11 You can scale Redis DB instances in two ways, vertical scaling and horizontal scaling. 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 concurrent restart is triggered and the leader pod may change after the restarting. 20 21 ::: 22 23 ### Before you start 24 25 Run the command below to check whether the cluster STATUS is `Running`. Otherwise, the following operations may fail. 26 27 ```bash 28 kbcli cluster list <name> 29 ``` 30 31 ***Example*** 32 33 ```bash 34 kbcli cluster list redis-cluster 35 > 36 NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME 37 redis-cluster default redis redis-7.0.6 Delete Running Apr 10,2023 16:21 UTC+0800 38 ``` 39 40 ### Steps 41 42 1. Change configuration. There are 3 ways to apply vertical scaling. 43 44 **Option 1.** (**Recommended**) Use kbcli 45 46 Configure the parameters `--components`, `--memory`, and `--cpu` and run the command. 47 48 ***Example*** 49 50 ```bash 51 kbcli cluster vscale redis-cluster \ 52 --components="redis" \ 53 --memory="4Gi" --cpu="2" \ 54 ``` 55 56 - `--components` describes the component name ready for vertical scaling. 57 - `--memory` describes the requested and limited size of the component memory. 58 - `--cpu` describes the requested and limited size of the component CPU. 59 60 **Option 2.** Create an OpsRequest 61 62 Apply an OpsRequest to the specified cluster. Configure the parameters according to your needs. 63 64 ```bash 65 kubectl apply -f - <<EOF 66 apiVersion: apps.kubeblocks.io/v1alpha1 67 kind: OpsRequest 68 metadata: 69 name: ops-vertical-scaling 70 spec: 71 clusterRef: redis-cluster 72 type: VerticalScaling 73 verticalScaling: 74 - componentName: redis 75 requests: 76 memory: "2Gi" 77 cpu: "1" 78 limits: 79 memory: "4Gi" 80 cpu: "2" 81 EOF 82 ``` 83 84 **Option 3.** Change the YAML file of the cluster 85 86 Change the configuration of `spec.componentSpecs.resources` in the YAML file. 87 88 `spec.componentSpecs.resources` controls the requests and limits of resources and changing them triggers a vertical scaling. 89 90 ***Example*** 91 92 ```YAML 93 apiVersion: apps.kubeblocks.io/v1alpha1 94 kind: Cluster 95 metadata: 96 name: redis-cluster 97 namespace: default 98 spec: 99 clusterDefinitionRef: redis 100 clusterVersionRef: redis-7.0.6 101 componentSpecs: 102 - name: redis 103 componentDefRef: redis 104 replicas: 1 105 resources: # Change values of resources 106 requests: 107 memory: "2Gi" 108 cpu: "1" 109 limits: 110 memory: "4Gi" 111 cpu: "2" 112 volumeClaimTemplates: 113 - name: data 114 spec: 115 accessModes: 116 - ReadWriteOnce 117 resources: 118 requests: 119 storage: 1Gi 120 terminationPolicy: Delete 121 ``` 122 123 2. Validate the vertical scaling. 124 125 Check the cluster status to identify the vertical scaling status. 126 127 ```bash 128 kbcli cluster list <name> 129 ``` 130 131 ***Example*** 132 133 ```bash 134 kbcli cluster list redis-cluster 135 > 136 NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME 137 redis-cluster default redis redis-7.0.6 Delete VerticalScaling Apr 10,2023 16:27 UTC+0800 138 ``` 139 140 - STATUS=VerticalScaling: it means the vertical scaling is in progress. 141 - STATUS=Running: it means the vertical scaling operation has been applied. 142 - 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. 143 > 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. 144 145 :::note 146 147 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. 148 149 ::: 150 151 3. Check whether the corresponding resources change. 152 153 ```bash 154 kbcli cluster describe redis-cluster 155 ``` 156 157 ## Horizontal scaling 158 159 Horizontal scaling changes the amount of pods. For example, you can apply horizontal scaling to scale up from three pods to five pods. The scaling process includes the backup and restoration of data. 160 161 ### Before you start 162 163 Check whether the cluster status is `Running`. Otherwise, the following operations may fail. 164 165 ```bash 166 kbcli cluster list <name> 167 ``` 168 169 ***Example*** 170 171 ```bash 172 kbcli cluster list redis-cluster 173 > 174 NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME 175 redis-cluster default redis redis-7.0.6 Delete Running Apr 10,2023 16:50 UTC+0800 176 ``` 177 178 ### Steps 179 180 1. Change configuration. There are 3 ways to apply horizontal scaling. 181 182 **Option 1.** (**Recommended**) Use kbcli 183 184 Configure the parameters `--components` and `--replicas`, and run the command. 185 186 ***Example*** 187 188 ```bash 189 kbcli cluster hscale redis-cluster \ 190 --components="redis" --replicas=2 191 ``` 192 193 - `--components` describes the component name ready for vertical scaling. 194 - `--replicas` describes the replica amount of a specified component. 195 196 **Option 2.** Create an OpsRequest 197 198 Apply an OpsRequest to the specified cluster. Configure the parameters according to your needs. 199 200 ```bash 201 kubectl apply -f - <<EOF 202 apiVersion: apps.kubeblocks.io/v1alpha1 203 kind: OpsRequest 204 metadata: 205 name: ops-horizontal-scaling 206 spec: 207 clusterRef: redis-cluster 208 type: HorizontalScaling 209 horizontalScaling: 210 - componentName: redis 211 replicas: 2 212 EOF 213 ``` 214 215 **Option 3.** Change the YAML file of the cluster 216 217 Change the value of `spec.componentSpecs.replicas` in the YAML file. `spec.componentSpecs.replicas` stands for the pod amount and changing this value triggers a horizontal scaling of a cluster. 218 219 ***Example*** 220 221 ```yaml 222 apiVersion: apps.kubeblocks.io/v1alpha1 223 kind: Cluster 224 metadata: 225 name: redis-cluster 226 namespace: default 227 spec: 228 clusterDefinitionRef: redis 229 clusterVersionRef: redis-7.0.6 230 componentSpecs: 231 - name: redis 232 componentDefRef: redis 233 replicas: 2 # Change the pod amount. 234 volumeClaimTemplates: 235 - name: data 236 spec: 237 accessModes: 238 - ReadWriteOnce 239 resources: 240 requests: 241 storage: 1Gi 242 terminationPolicy: Delete 243 ``` 244 245 2. Validate the horizontal scaling operation. 246 247 Check the cluster STATUS to identify the horizontal scaling status. 248 249 ```bash 250 kbcli cluster list <name> 251 ``` 252 253 ***Example*** 254 255 ```bash 256 kbcli cluster list redis-cluster 257 > 258 NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME 259 redis-cluster default redis redis-7.0.6 Delete HorizontalScaling Apr 10,2023 16:58 UTC+0800 260 ``` 261 262 - STATUS=HorizontalScaling: it means horizontal scaling is in progress. 263 - STATUS=Running: it means horizontal scaling has been applied. 264 265 ### Handle the snapshot exception 266 267 If `STATUS=ConditionsError` occurs during the horizontal scaling process, you can find the cause from `cluster.status.condition.message` for troubleshooting. 268 In the example below, a snapshot exception occurs. 269 270 ```bash 271 Status: 272 conditions: 273 - lastTransitionTime: "2023-04-10T18:20:26Z" 274 message: VolumeSnapshot/redis-cluster-redis-scaling-dbqgp: Failed to set default snapshot 275 class with error cannot find default snapshot class 276 reason: ApplyResourcesFailed 277 status: "False" 278 type: ApplyResources 279 ``` 280 281 ***Reason*** 282 283 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. 284 285 ***Steps:*** 286 287 1. Configure the VolumeSnapshotClass by running the command below. 288 289 ```bash 290 kubectl create -f - <<EOF 291 apiVersion: snapshot.storage.k8s.io/v1 292 kind: VolumeSnapshotClass 293 metadata: 294 name: csi-aws-vsc 295 annotations: 296 snapshot.storage.kubernetes.io/is-default-class: "true" 297 driver: ebs.csi.aws.com 298 deletionPolicy: Delete 299 EOF 300 ``` 301 302 2. Delete the wrong backup (volumesnapshot is generated by backup) and volumesnapshot resources. 303 304 ```bash 305 kubectl delete backup -l app.kubernetes.io/instance=redis-cluster 306 307 kubectl delete volumesnapshot -l app.kubernetes.io/instance=redis-cluster 308 ``` 309 310 ***Result*** 311 312 The horizontal scaling continues after the backup and volumesnapshot are deleted and the cluster restores to running status.