Skip to main content
Version: Preview

Create and connect to an ApeCloud MySQL cluster

This tutorial shows how to create and connect to an ApeCloud MySQL cluster.

Create a MySQL cluster

Before you start

  • Install kbcli if you want to create and connect a MySQL cluster by kbcli.

  • Install KubeBlocks by kbcli or by Helm.

  • Check whether the ApeCloud MySQL Addon is enabled. The ApeCloud MySQL Addon is enabled by KubeBlocks by default. If you disable it when installing KubeBlocks,enable it first.

    kbcli addon list
    >
    NAME VERSION PROVIDER STATUS AUTO-INSTALL
    ...
    apecloud-mysql 0.9.0 apecloud Enabled true
    ...
  • View all the database types and versions available for creating a cluster.

    kbcli clusterdefinition list

    kbcli clusterversion list
  • To keep things isolated, create a separate namespace called demo throughout this tutorial.

    kubectl create namespace demo

Create a cluster

KubeBlocks supports creating two types of ApeCloud MySQL clusters: Standalone and RaftGroup Cluster. Standalone only supports one replica and can be used in scenarios with lower requirements for availability. For scenarios with high availability requirements, it is recommended to create a RaftGroup Cluster, which creates a cluster with three replicas. To ensure high availability, all replicas are distributed on different nodes by default.

  1. Create an ApeCloud MySQL cluster.

    Below are some common examples to create a cluster with default settings. If you want to customize your cluster specifications, kbcli provides various options, such as setting cluster version, termination policy, CPU, and memory. You can view these options by adding --help or -h flag.

    kbcli cluster create apecloud-mysql --help

    kbcli cluster create apecloud-mysql -h

    Create a Standalone.

    kbcli cluster create mycluster --cluster-definition apecloud-mysql --namespace demo

    Create a RaftGroup Cluster.

    kbcli cluster create mycluster --cluster-definition apecloud-mysql --set replicas=3 --namespace demo

    If you only have one node for deploying a RaftGroup Cluster, set the topology-keys as null when creating a RaftGroup Cluster. But you should note that for a production environment, it is not recommended to deploy all replicas on one node, which may decrease the cluster availability.

    kbcli cluster create mycluster --cluster-definition apecloud-mysql --set replicas=3 --topology-keys null --namespace demo
  2. Verify whether this cluster is created successfully.

    kbcli cluster list -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

Connect to an ApeCloud MySQL Cluster

kbcli cluster connect mycluster  -n demo

For the detailed database connection guide, refer to Connect database.