Validate the MySQL cluster
After you applied the Cennso Database CRs to the Management Cluster, the MySQL cluster is deployed. It consists of multiple MySQL instances. If you use node-local volumes, the instances run on the nodes specified by spec.instances[].storage.node. Otherwise, they run on the nodes where the storage class provides their volumes.
One of the MySQL instances is the primary instance that accepts both reads and writes. The second is a read replica only. You can differentiate them by the mysql.percona.com/primary label. This label has the value true for the MySQL instance selected as the primary instance.
This document describes the validation procedures after your MySQL cluster is up and running.
Connect to the MySQL cluster
Applications must use HAProxy instead of connecting directly to a pod or a service. HAProxy exposes the following ports:
- port
3306for a read-write MySQL instance - port
3307for a read-only MySQL instance(s)
Connecting directly to a MySQL pod or a MySQL service doesn't provide the roles distinction and doesn't disconnect the application once a read-write MySQL instance becomes a read-only one.
The Cennso Database extension exposes two kinds of HAProxy endpoints:
- In-cluster endpoint - targets all HAProxy pods. Use it for workloads running inside the same Core Cluster as the MySQL cluster.
- Per-instance external endpoint - targets a single HAProxy pod. Use it when you want to address a specific instance or expose it through an external IP.
In-cluster endpoint
The Cennso Database extension creates a Kubernetes Service that fronts all HAProxy pods. Applications running in the Core Cluster must use this Service as the MySQL endpoint. The endpoint is reachable via ps-db-{DBINSTANCE-NAME}-haproxy:{PORT} or ps-db-{DBINSTANCE-NAME}-haproxy.{DATABASE-CLUSTER-NAMESPACE}.svc.cluster.local:{PORT}. The DBINSTANCE-NAME here is the value specified in the metadata.name of the DBInstance claim. The port can be either 3306 for the primary MySQL instance or 3307 for the read replica instance.
For example, to connect from a Pod in the same Core Cluster, run:
To use an encrypted connection, add the --ssl-mode=REQUIRED option:
The root password is stored in the ps-db-{DBINSTANCE-NAME}-secrets Kubernetes Secret in the same namespace as the MySQL cluster. You can retrieve it with:
Per-instance external endpoint
Note
Per-instance endpoint supports only port 3306.
In addition to the in-cluster endpoint, the Cennso Database extension creates one Kubernetes Service per HAProxy pod. Each of these Services selects a single HAProxy pod, which is useful when you want to address a specific instance or expose it through an external IP. The endpoint is reachable via db-{DBINSTANCE-NAME}-service-{INSTANCE-NUMBER}-ext:3306. The DBINSTANCE-NAME here is the value specified in the metadata.name of the DBInstance claim. The {INSTANCE-NUMBER} is the key from spec.instances in the DBInstance CR (for example, 0 or 1). If you set spec.instances[].storage.externalIP, the corresponding Service exposes the configured external IP, which lets you reach the MySQL cluster from the outside of the Core Cluster.
Validate replication state
Once both primary and secondary instances are ready, you can check the replication status. To do that, execute the following steps:
Get credentials for the
rootuser to access the database instances:bash{DATABASE-CLUSTER-NAMESPACE}is the Kubernetes Namespace where the Cennso Database is deployed, and the{DBINSTANCE-NAME}is the value specified in the metadata.name of theDBInstanceclaim.Connect to the secondary MySQL instance with the credentials obtained in the previous step. For information on how to connect to the MySQL replica, read the Connect to the MySQL cluster section.
Execute the following SQL query to get the status of your MySQL instance:
sqlAmong various fields in the output, you should see the following:
textThis means that you have a fully working and ready-to-use MySQL cluster.