Create and connect to a MySQL cluster
This tutorial shows how to create and connect to a MySQL cluster.
Create a MySQL cluster
Before you start
Make sure the MySQL addon is enabled. If this addon is not enabled, enable it first.
kbcli addon list
>
NAME VERSION PROVIDER STATUS AUTO-INSTALL
...
mysql 0.9.1 community 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 Replication 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 Replication Cluster, which creates a cluster with two replicas. To ensure high availability, all replicas are distributed on different nodes by default.
Create a Standalone.
kbcli cluster create mycluster --cluster-definition mysql
Create a Replication Cluster.
kbcli cluster create mycluster --cluster-definition mysql --set replicas=2
If you only have one node for deploying a Replication Cluster, set the topology-keys
as null
when creating a Replication Cluster.
kbcli cluster create mycluster --cluster-definition mysql --set replicas=2 --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 mycluster --cluster-definition mysql --cluster-version 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 a MySQL Cluster
kbcli cluster connect <clustername> --namespace <name>
For the detailed database connection guide, refer to Connect database.