New to KubeDB? Please start here.

Using Custom Configuration File

KubeDB supports providing custom configuration for ProxySQL. This tutorial will show you how to use KubeDB to run a ProxySQL with custom configuration.

Before You Begin

  • At first, you need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using kind.

  • Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps here.

  • To keep things isolated, this tutorial uses a separate namespace called demo throughout this tutorial.

    $ kubectl create ns demo
    namespace/demo created
    $ kubectl get ns demo
    demo    Active  5s

Note: YAML files used in this tutorial are stored in docs/examples/proxysql folder in GitHub repository kubedb/docs.


ProxySQL allows to configure via configuration file. The default configuration for ProxySQL can be found in /etc/proxysql.cnf file. In our Docker image (for ProxySQL), we used the file /etc/configuration/custom-proxysql.cnf as the custom configuration file. The procedure is such that if the configuration file exist, ProxySQL instance will use combined startup settings from both /etc/proxysql.cnf and /etc/configuration/custom-proxysql.cnf files. This custom configuration will overwrite the existing default one. For example config file:

To know more about configuring ProxySQL see configuration file and variables.

At first, you have to create a config file with name custom-proxysql.cnf containing your desired configurations. Then you have to put this file into a volume. You have to specify this volume in .spec.configSecret section while creating ProxySQL object. KubeDB will mount this volume into /etc/custom-config directory of the ProxySQL Pod.

In this tutorial, we will configure mysql-connect_timeout_server via the custom-proxysql.cnf file. We will use configMap as volume source.

Custom Configuration

At first, let’s create custom-proxysql.cnf file setting mysql-connect_timeout_server parameter.

Note: We recommend to include the line interfaces="" here in the mysql_variables block. Though without this line, ProxySQL will work fine but we recommend to include it. The important thing you should keep in mind here is that never change the credential for admin interface for current version of ProxySQL image. It must be admin:admin (:).

cat <<EOF > custom-proxysql.cnf

$ cat custom-proxysql.cnf

Here, connect_timeout_server is set to 20 secondes in mili-second.

Now, create a configMap with this configuration file.

 $ kubectl create configmap -n demo my-custom-config --from-file=./custom-proxysql.cnf
configmap/my-custom-config created

Verify the config map has the configuration file.

$ kubectl get configmap -n demo my-custom-config -o yaml
apiVersion: v1
  my-config.cnf: |
kind: ConfigMap
  name: my-custom-config
  namespace: demo

Note: For this tutorial there must be a MySQL object with name my-group (Group Replication supported) running in the demo namespace in the cluster. You can deploy one by following section create MySQL object with Group Replication.

Now, create ProxySQL object specifying .spec.configSecret field.

$ kubectl apply -f created

Below is the YAML for the ProxySQL object we just created.

kind: ProxySQL
  name: custom-proxysql
  namespace: demo
  version: "2.0.4"
  replicas: 1
  mode: GroupReplication
      apiGroup: ""
      kind: MySQL
      name: my-group
    replicas: 3
    name: my-custom-config

Now, wait a few minutes. KubeDB operator will create necessary statefulset, services, secret etc. If everything goes well, we will see that a Pod with the name custom-proxysql-0 has been created.

Check that the StatefulSet’s Pod is running

$ kubectl get pod -n demo
NAME                READY     STATUS    RESTARTS   AGE
custom-proxysql-0   1/1       Running   0          44s

Check the Pod’s log,

$ kubectl logs -f -n demo custom-proxysql-0
2019/11/28 15:58:41 [] [INFO] Applying custom config using cmd 'proxysql -c /etc/configuration/custom-proxysql.cnf --reload -f  &'
2019/11/28 15:58:41 [] [INFO] Configuring proxysql ...
2019/11/28 15:58:41 [] [] From
2019/11/28 15:58:41 [] [INFO] Provided peers are
2019/11/28 15:58:41 [] [INFO] Waiting for host to be online ...
2019-11-28 15:58:41 [INFO] Using config file /etc/configuration/custom-proxysql.cnf
2019-11-28 15:58:41 [INFO] No SSL keys/certificates found in datadir (/). Generating new keys/certificates.

Now, we will check if the ProxySQL has started with the custom configuration we have provided.

kubectl exec -it -n demo custom-proxysql-0 -- mysql -uadmin -padmin -h127.0.0.1 -P6032 --prompt="ProxySQL [Admin]> "
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

ProxySQL [Admin]> show global variables;
| Variable_name                                       | Value                |
| admin-admin_credentials                             | admin:admin          |
| admin-checksum_mysql_query_rules                    | true                 |
| admin-checksum_mysql_servers                        | true                 |
| admin-checksum_mysql_users                          | true                 |
| admin-mysql_ifaces                                  |         |

| mysql-connect_timeout_server                        | 20000                |
| mysql-monitor_username                              | proxysql             |
146 rows in set (0.00 sec)

Cleaning up

To cleanup the Kubernetes resources created by this tutorial, run:

$ kubectl delete proxysql -n demo custom-proxysql

$ kubectl delete configmap my-custom-config -n demo
$ rm ./custom-proxysql.cnf
$ kubectl delete my -n demo my-group

$ kubectl delete ns demo

If you would like to uninstall KubeDB operator, please follow the steps here.

Next Steps