Topologies
Operations
Backup And Restores
Custom Secret
Monitoring
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.
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 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.
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.
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
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
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:
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
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
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 |
+-----------+
In this guide, you learned how to:
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.