MySQL Router Configuration¶
MySQL Router is lightweight middleware that provides transparent routing between your application and back-end MySQL servers. MySQL Router is part of the Operator and is deployed during the installation. MySQL Router can be used as an alternative to HAProxy based load balancing when group replication between MySQL instances is turned on.
To use the Router, enable it and make sure that HAProxy is disabled.
Enable MySQL Router¶
-
Edit the
deploy/cr.yamlfile... mysql: clusterType: group-replication ... proxy: haproxy: enabled: false ... router: enabled: true ... -
Update the cluster to apply the new configuration:
kubectl apply -f deploy/cr.yamlWhen the process is over your cluster will obtain the
readystatus. You can check it with the following command:kubectl get psExpected output
NAME REPLICATION ENDPOINT STATE MYSQL ORCHESTRATOR HAPROXY ROUTER AGE ps-cluster1 group-replication ps-cluster1-router.default ready 3 3 53m
Configure MySQL Router¶
When enabled, the MySQL Router operates with the reasonable default settings and can be used in a variety of use cases such as high-availability and scalability.
If you need to fine-tune the Router for the needs of your application and/or usage scenario, you can do this using the following methods:
- Edit the
deploy/cr.yamlfile - Use the ConfigMap
To illustrate this, let’s override the verbosity level and set it to INFO.
Before you start, check that you have enabled the MySQL Router for the Operator.
The router.configuration subsection of the deploy.cr.yaml file contains the MySQL Router configuration.
-
To change the verbosity level, edit the configuration file as follows:
configuration: | [default] logging_folder=/tmp/router/log [logger] level=INFO -
Update the cluster to apply the new configuration
kubectl apply -f deploy.cr.yaml
A ConfigMap is a Kubernetes mechanism to pass or update configuration data inside a containerized application.
You can create a ConfigMap from a file using the kubectl create configmap command. For more information about ConfigMap usage, see Configure a Pod to use a ConfigMap .
To pass the new verbosity level of MySQL Router to the Operator using the ConfigMap, do the following:
-
Create the
mysqlrouter.confconfiguration file and specify the new verbosity level within.[logger] level = INFO -
Get the name of your cluster to pass the configuration
kubectl get ps -
Create the ConfigMap. You should use the combination of the cluster name with the
-routersuffix as the naming convention for the ConfigMap. For example, to create the ConfigMap for the clusterps-cluster1, the command is the following:kubectl create configmap ps-cluster1-router --from-file=mysqlrouter.confReplace the
ps-cluster1with the corresponding name of your cluster. -
View the created ConfigMap using the following command:
kubectl describe configmaps ps-cluster1-mysql
Created: September 5, 2023