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. List All Available MySQL Versions
  5. Upgrading the MySQL Version
    1. Identify the Current Primary and Secondary Instances
    2. Apply the Upgrade
    3. Monitor the Upgrade Process
  6. Verification
    1. Check Cluster Status
    2. Verify the MySQL Version
  7. Summary

Upgrading the Minor Version of a MySQL Cluster in KubeBlocks

This guide walks you through the deployment and minor version upgrade of a MySQL cluster managed by KubeBlocks, ensuring minimal downtime during the process.

To minimize the impact on database availability, the upgrade process starts with the replicas (secondary instances). Once the replicas are upgraded, a switchover operation promotes one of the upgraded replicas to primary. The switchover process is very fast, typically completing in a few hundred milliseconds. After the switchover, the original primary instance is upgraded, ensuring minimal disruption to the application.

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 cluster status until it transitions to the Running state:

kubectl get cluster example-mysql-cluster -n demo -w

Example Output:

NAME                     CLUSTER-DEFINITION   TERMINATION-POLICY   STATUS    AGE
example-mysql-cluster   mysql                Delete               Creating   8s
example-mysql-cluster   mysql                Delete               Running    2m41s

Once the cluster status becomes Running, your MySQL cluster is ready for use.

List All Available MySQL Versions

Use the following command to display the MySQL versions supported by your KubeBlocks installation:

kubectl get cmpv mysql

Expected Output:

NAME    VERSIONS                                                                                         STATUS      AGE
mysql   8.4.2,8.4.1,8.4.0,8.0.39,8.0.38,8.0.37,8.0.36,8.0.35,8.0.34,8.0.33,8.0.32,8.0.31,8.0.30,5.7.44   Available   11d

Note: The list of supported versions may vary depending on your KubeBlocks version.

Upgrading the MySQL Version

Identify the Current Primary and Secondary Instances

Run the following command to identify the roles of the cluster instances:

kubectl get pods -n demo -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.labels.kubeblocks\.io/role}{"\n"}{end}'

Expected Output:

example-mysql-cluster-mysql-0	primary
example-mysql-cluster-mysql-1	secondary

Apply the Upgrade

To upgrade the MySQL version, modify the serviceVersion field in the Cluster resource. In this example, we will upgrade the MySQL version from 8.0.35 to 8.0.39:

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.39      # Update version from 8.0.35 to 8.0.39
      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 Upgrade Process

During the upgrade, observe the changes in the cluster's Pods:

kubectl get pods -n demo -w

Expected Output:

NAME                            READY   STATUS    RESTARTS   AGE
example-mysql-cluster-mysql-0   4/4     Running   0          97s
example-mysql-cluster-mysql-1   4/4     Running   0          50s
example-mysql-cluster-mysql-1   3/4     Running   2 (2s ago)   68s
example-mysql-cluster-mysql-0   4/4     Running   2 (6s ago)   2m6s

Key Observations:

  • The replica ('example-mysql-cluster-mysql-1') is upgraded first.
  • A switchover operation occurs, making the replica the new primary.
  • Finally, the original primary ('example-mysql-cluster-mysql-0') is upgraded.

After the upgrade is completed, roles are switched:

kubectl get pods -n demo -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.labels.kubeblocks\.io/role}{"\n"}{end}'

Updated Roles:

example-mysql-cluster-mysql-0	secondary
example-mysql-cluster-mysql-1	primary

Verification

Check Cluster Status

Ensure the cluster is in the Running state:

kubectl get cluster example-mysql-cluster -n demo -w

Expected Output:

NAME                    CLUSTER-DEFINITION   TERMINATION-POLICY   STATUS    AGE
example-mysql-cluster   mysql                Delete               Running   17m

Verify the MySQL Version

Retrieve the MySQL root credentials:

kubectl get secrets -n demo example-mysql-cluster-mysql-account-root -o jsonpath='{.data.password}' | base64 -d

Expected Output:

79vJW1Vg43

Connect to the upgraded instances and verify the MySQL version:

kubectl exec -ti -n demo example-mysql-cluster-mysql-1 -- mysql -uroot -p79vJW1Vg43 -e "SELECT VERSION();"

Example Output:

+-----------+
| VERSION() |
+-----------+
| 8.0.39    |
+-----------+

Summary

In this guide, you learned how to:

  • Deploy a MySQL semi-synchronous cluster using KubeBlocks.
  • Perform a rolling upgrade of the MySQL minor version with minimal downtime.
  • Verify that the upgrade was successful.

This rolling upgrade strategy ensures high availability by upgrading the replicas first, performing a switchover, and then upgrading the original primary instance. strategy ensures high availability by upgrading the replicas first, performing a switchover, and then upgrading the original primary instance.

© 2025 ApeCloud PTE. Ltd.