KubeBlocks
BlogsKubeBlocks Cloud
⌘K
​

Introduction

ApeCloud MySQL introduction
KubeBlocks for ApeCloud MySQL

Cluster Management

Create and connect
Scale
Expand volume
Restart
Stop/Start
Switchover
Delete protection

Configuration

Configuration

High Availability

Failure simulation and automatic recovery

Proxy

Introduction
ApeCloud MySQL Proxy Cluster
  1. Before you start
  2. Initiate the switchover
  3. Verify the switchover
  4. Handle an exception

Switch over an ApeCloud MySQL cluster

You can initiate a switchover for an ApeCloud MySQL RaftGroup by executing the kbcli or kubectl command. Then KubeBlocks switches the instance roles.

Before you start

  • Make sure the cluster is running normally.

    kubectl get cluster mycluster -n demo
    >
    NAME        CLUSTER-DEFINITION   VERSION           TERMINATION-POLICY   STATUS    AGE
    mycluster   apecloud-mysql       ac-mysql-8.0.30   Delete               Running   27m
    
    kbcli cluster list mycluster -n demo
    >
    NAME        NAMESPACE   CLUSTER-DEFINITION   VERSION           TERMINATION-POLICY   STATUS    CREATED-TIME
    mycluster   demo        apecloud-mysql       ac-mysql-8.0.30   Delete               Running   Sep 19,2024 16:01 UTC+0800
    
  • Check whether the following role probe parameters exist to verify whether the role probe is enabled.

    kubectl get cd apecloud-mysql -o yaml
    >
    probes:
      roleProbe:
        failureThreshold: 2
        periodSeconds: 1
        timeoutSeconds: 1
    

Initiate the switchover

You can switch over a follower of an ApeCloud MySQL RaftGroup to the leader role, and the former leader instance to a follower.

The value of instanceName decides whether a new leader instance is specified for the switchover.

  • Initiate a switchover with no leader instance specified.

    kubectl apply -f -<<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
      name: mycluster-switchover
      namespace: demo
    spec:
      clusterName: mycluster
      type: Switchover
      switchover:
      - componentName: apecloud-mysql
        instanceName: '*'
    EOF
    
  • Initiate a switchover with a specified new leader instance.

    kubectl apply -f -<<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
      name: mycluster-switchover
      namespace: demo
    spec:
      clusterName: mycluster
      type: Switchover
      switchover:
      - componentName: apecloud-mysql
        instanceName: 'mycluster-mysql-2'
    EOF
    
  • Initiate a switchover with no leader instance specified.

    kbcli cluster promote mycluster -n demo
    
  • Initiate a switchover with a specified new leader instance.

    kbcli cluster promote mycluster --instance='mycluster-mysql-2' -n demo
    
  • If there are multiple components, you can use --components to specify a component.

    kbcli cluster promote mycluster --instance='mycluster-mysql-2' --components='apecloud-mysql' -n demo
    

Verify the switchover

Check the instance status to verify whether the switchover is performed successfully.

kubectl get pods -n demo
kbcli cluster list-instances -n demo

Handle an exception

If an error occurs, refer to Handle an exception to troubleshoot the operation.

© 2025 ApeCloud PTE. Ltd.