Topologies
Operations
Backup And Restores
Custom Secret
Monitoring
This guide explains how to perform vertical scaling in a MySQL cluster managed by KubeBlocks. Vertical scaling adjusts the resource limits and requests (such as CPU and memory) allocated to the cluster components, allowing for better performance or resource optimization.
Vertical scaling involves increasing or decreasing the resources (e.g., CPU and memory) allocated to a running database cluster. Unlike horizontal scaling, which adjusts the number of replicas, vertical scaling focuses on scaling the capacity of individual Pods.
Resources that can be scaled include:
KubeBlocks ensures seamless vertical scaling by carefully orchestrating Pod restarts to minimize downtime. For example:
Before proceeding, ensure the following:
kubectl create ns demo
namespace/demo created
Deploy a 2-node semi-sync MySQL cluster (1 primary, 1 secondary):
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: example-mysql-cluster
namespace: demo
spec:
clusterDef: mysql
topology: semisync
terminationPolicy: Delete
componentSpecs:
- name: mysql
serviceVersion: 8.0.35
replicas: 2
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
EOF
Monitor the status of the MySQL cluster as it is created:
kubectl get cluster -n demo -w
Example Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
example-mysql-cluster mysql Delete Creating 66s
example-mysql-cluster mysql Delete Running 72s
Option 1: Using VerticalScaling OpsRequest
Apply the following YAML to scale up the resources for the mysql component:
kubectl apply -f - <<EOF
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: example-mysql-cluster-vscale-ops
namespace: demo
spec:
clusterName: example-mysql-cluster
type: VerticalScaling
verticalScaling:
- componentName: mysql
requests:
cpu: '1'
memory: 1Gi
limits:
cpu: '1'
memory: 1Gi
EOF
What Happens During Vertical Scaling?
You can check the progress of the scaling operation with the following command:
kubectl describe ops example-mysql-cluster-vscale-ops -n demo
Expected Result:
Status:
Phase: Succeed
Progress: 2/2
...
Option 2: Direct Cluster API Update
Alternatively, you may update spec.componentSpecs.resources
field to the desired resources for vertical scale.
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: example-mysql-cluster
namespace: demo
spec:
clusterDef: mysql
topology: semisync
terminationPolicy: Delete
componentSpecs:
- name: mysql
serviceVersion: 8.0.35
replicas: 2
resources:
requests:
cpu: "1" # Update the resources to your need.
memory: "1Gi" # Update the resources to your need.
limits:
cpu: "1" # Update the resources to your need.
memory: "1Gi" # Update the resources to your need.
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
EOF
Verify the updated resources by inspecting the cluster configuration or Pod details:
kbcli cluster describe example-mysql-cluster -n demo
Expected Output:
Resources Allocation:
COMPONENT INSTANCE-TEMPLATE CPU(REQUEST/LIMIT) MEMORY(REQUEST/LIMIT) STORAGE-SIZE STORAGE-CLASS
mysql 1 / 1 1Gi / 1Gi data:20Gi <none>
In this guide, you learned how to:
Vertical scaling is a powerful tool for optimizing resource utilization and adapting to changing workload demands, ensuring your MySQL cluster remains performant and resilient.