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
Make sure the ApeCloud MySQL addon is enabled. If this addon is not enabled, enable it first.
kbcli addon list
>
NAME TYPE STATUS EXTRAS AUTO-INSTALL
...
apecloud-mysql Helm Enabled true
...View all the database types and versions available for creating a cluster.
kbcli clusterdefinition list
kbcli clusterversion listTo 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 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.
Create a Standalone.
kbcli cluster create <clustername> --cluster-definition apecloud-mysql
Create a RaftGroup Cluster.
kbcli cluster create <clustername> --cluster-definition apecloud-mysql --set replicas=3 <clustername>
If you only have one node for deploying a RaftGroup Cluster, set the topology-keys
as null
when creating a RaftGroup Cluster.
kbcli cluster create <clustername> --cluster-definition apecloud-mysql --set replicas=3 --topology-keys null
If you want to specify a cluster version, you can first view the available versions and use --cluster-version
to specify a version.
kbcli clusterversion list
kbcli cluster create <clustername> --cluster-definition apecloud-mysql --cluster-version ac-mysql-8.0.30
In the production environment, it is not recommended to deploy all replicas on one node, which may decrease the cluster availability.
View more flags for creating a cluster to create a cluster with customized specifications.
kbcli cluster create --help
Connect to an ApeCloud MySQL Cluster
kbcli cluster connect <clustername> --namespace <name>
For the detailed database connection guide, refer to Connect database.