Topologies
Operations
Backup And Restores
Custom Secret
Monitoring
This guide explains how to expand the Persistent Volume Claims (PVCs) in a MySQL cluster managed by KubeBlocks. Volume expansion allows you to increase storage capacity dynamically, ensuring your database can scale seamlessly as data grows. If supported by the underlying storage class, this operation can be performed without downtime.
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 32s
example-mysql-cluster mysql Delete Running 3m
Volume expansion allows you to increase the size of a Persistent Volume Claim (PVC) after it has been created. This feature was introduced in Kubernetes v1.11 and became generally available (GA) in Kubernetes v1.24.
Key points to remember:
List all available storage classes and verify if volume expansion is supported by checking the ALLOWVOLUMEEXPANSION field:
kubectl get storageclass
Example Output:
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
gp2 kubernetes.io/aws-ebs Delete WaitForFirstConsumer false 4d10h
kb-default-sc ebs.csi.aws.com Delete WaitForFirstConsumer true 3d7h
sc-s3-repo-2qsxfh ru.yandex.s3.csi Retain Immediate false 3d7h
Ensure the storage class you are using has ALLOWVOLUMEEXPANSION set to true. If it is false, the storage class does not support volume expansion.
You can expand the volume in one of two ways:
Option 1: Using VolumeExpansion OpsRequest
Apply the following YAML to increase the volume size for the mysql component:
kubectl apply -f - <<EOF
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: example-mysql-expand-volume-ops
namespace: demo
spec:
clusterName: example-mysql-cluster
type: VolumeExpansion
volumeExpansion:
- componentName: mysql
volumeClaimTemplates:
- name: data
storage: 30Gi
EOF
You can check the progress of the scaling operation with the following command:
kubectl describe ops example-mysql-expand-volume-ops -n demo
Expected Result:
Status:
Phase: Succeed
Progress: 1/1
...
Once completed, the PVC size will be updated.
Option 2: Direct Cluster API Update
Alternatively, you may update the spec.componentSpecs.volumeClaimTemplates.spec.resources.requests.storage
field to the desired size.
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: 30Gi # specify new size, and make sure it is larger than the current size
EOF
KubeBlocks will automatically update the PVC size based on the new specifications.
Use the following command to inspect the updated cluster configuration:
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 500m / 500m 512Mi / 512Mi data:30Gi <none>
The volume size for the data PVC has been updated to the specified value (e.g., 30Gi in this case).
Check the status of the PVCs in the cluster to confirm that the resize operation has completed:
kubectl get pvc -l app.kubernetes.io/instance=example-mysql-cluster -n demo
Expected Output:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
example-mysql-cluster-mysql-data-0 Bound pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 30Gi RWO kb-default-sc 10m
example-mysql-cluster-mysql-data-1 Bound pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 30Gi RWO kb-default-sc 10m
ALLOWVOLUMEEXPANSION
).In this guide, you learned how to:
With volume expansion, you can efficiently scale your MySQL cluster's storage capacity without service interruptions, ensuring your database can grow alongside your application needs.