Skip to content

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

  1. Edit the deploy/cr.yaml file

    ...
    mysql:
      clusterType: group-replication
      ...
    proxy:
      haproxy:
        enabled: false
        ...
      router:
        enabled: true
        ...
    
  2. Update the cluster to apply the new configuration:

    $ kubectl apply -f deploy/cr.yaml
    

    When the process is over your cluster will obtain the ready status. You can check it with the following command:

    $ kubectl get ps
    
    Expected output
    NAME       REPLICATION         ENDPOINT                  STATE   MYSQL   ORCHESTRATOR   HAPROXY   ROUTER   AGE
    cluster1   group-replication   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.yaml file
  • 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.

  1. To change the verbosity level, edit the configuration file as follows:

    configuration: |
     [default]
     logging_folder=/tmp/router/log
     [logger]
     level=INFO
    
  2. 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:

  1. Create the mysqlrouter.conf configuration file and specify the new verbosity level within.

    [logger]
    level = INFO
    
  2. Get the name of your cluster to pass the configuration

    $ kubectl get ps
    
  3. Create the ConfigMap. You should use the combination of the cluster name with the -router suffix as the naming convention for the ConfigMap. For example, to create the ConfigMap for the cluster cluster1, the command is the following:

    $ kubectl create configmap cluster1-router --from-file=mysqlrouter.conf
    

    Replace the cluster1 with the corresponding name of your cluster.

  4. View the created ConfigMap using the following command:

    $ kubectl describe configmaps cluster1-mysql
    

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services. Join K8S Squad to benefit from early access to features and “ask me anything” sessions with the Experts.


Last update: 2024-10-29