KubeBlocks
BlogsKubeBlocks Cloud
Overview
Quickstart

Topologies

MySQL Semi-Synchronous Cluster
MySQL Cluster with ProxySQL
MySQL Group Replication Cluster
MySQL Group Replication with ProxySQL
MySQL Cluster with Orchestrator
MySQL with Orchestrator & ProxySQL

Operations

Lifecycle Management
Vertical Scaling
Horizontal Scaling
Volume Expansion
Manage MySQL Services
Minor Version Upgrade
Modify MySQL Parameters
Planned Switchover in MySQL
Decommission MySQL Replica
Recovering MySQL Replica

Backup And Restores

Create BackupRepo
Create Full Backup
Scheduled Backups
Scheduled Continuous Backup
Restore MySQL Cluster
Restore with PITR

Custom Secret

Custom Password
Custom Password Policy

TLS

MySQL Cluster with TLS
MySQL Cluster with User-Provided TLS
MySQL Cluster with mTLS

Monitoring

Observability for MySQL Clusters

Advanced Pod Management

Custom Scheduling Policies
Custom Pod Resources
Pod Management Parallelism
Using OnDelete for Controlled Pod Updates
Gradual Rolling Update
  1. Prerequisites
  2. Deploy a MySQL Semi-Synchronous Cluster
  3. Verifying the Deployment
  4. Expand volume
    1. Check the Storage Class for Volume Expansion Support
  5. Verification
  6. Key Considerations
  7. Summary

Expanding Volume in a MySQL Cluster

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.

Prerequisites

Before proceeding, ensure the following:

  • Environment Setup:
    • A Kubernetes cluster is up and running.
    • The kubectl CLI tool is configured to communicate with your cluster.
    • KubeBlocks CLI and KubeBlocks Operator are installed. Follow the installation instructions here.
  • Namespace Preparation: To keep resources isolated, create a dedicated namespace for this tutorial:
kubectl create ns demo
namespace/demo created

Deploy a MySQL Semi-Synchronous Cluster

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

Verifying the Deployment

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

Expand volume

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:

  • Supported Storage Class: The storage class used for the PVC must support volume expansion.
  • No Downtime: In most cases, volume expansion can be performed without downtime.
  • Incremental Expansion: The new size must be larger than the current size.

Check the Storage Class for Volume Expansion Support

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.

Verification

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

Key Considerations

  1. Ensure the storage class supports volume expansion (check ALLOWVOLUMEEXPANSION).
  2. The new size must be larger than the current size.
  3. Volume expansion may require additional configurations depending on the storage provider.

Summary

In this guide, you learned how to:

  1. Verify storage class compatibility for volume expansion.
  2. Perform volume expansion using either:
    • OpsRequest for dynamic updates.
    • Cluster API for manual updates.
  3. Verify the updated PVC size and ensure the resize operation is complete.

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.

© 2025 ApeCloud PTE. Ltd.