Integrating mysql clusters into your own helm charts

How to integrate the MySQL operator with your application.

After cluster creation, you can update the provided secret with a new field named DB_CONNECT_URL that contains a DSN to connect to the writable cluster endpoint. You can check the _helper.tpl file for more insights.

The MySQL operator provides 3 services to access the nodes:

  • <cluster_name>-mysql-master is the service that points to the master node and this endpoint should be used for writes. This service is usually used to construct the DSN.
  • <cluster_name>-mysql is the service that routes traffic to all healthy nodes from the cluster. You should use this endpoint for reads.
  • mysql is the service used internally to access all nodes within a namespace. You can use this service to access a specific node (e.g. <cluster_name>-mysql-0.mysql.<namespace>)

We use helm to deploy our application into Kubernetes, so we updated our charts to use the MySQL operator to provide one cluster per application.

Using Helm

Usually a cluster of MySQL is needed alongside with an application, that’s why we provide a Helm chart for easy deployment of a MySQL cluster. The chart can be found in presslabs chart repository and installed like the operator. Below is illustrated how this chart can be integrated with your application to provision a MySQL cluster.

Add MySQL Cluster chart as dependency

In your chart add in requirements.yaml under dependencies section the following:

  - name: mysql-cluster
    version: 0.2.0
    condition: mysql.enabled
    alias: mysql

Once dependencies are configured run helm dependency update to fetch related charts.

More information about chart requirements can be found in the official documentation .

Configure your chart’s values.yaml file

You can configure the cluster by providing values under the mysql key. A comprehensive description can be found in the chart <code>values.yaml</code> file.

  enabled: true
  rootPassword: <secure>
  appUser: <user name>
  appPassword: <user password>
  appDatabase: <app database>

Use into your application

In your deployment add an environment variable that point to the DB_CONNECT_URL field from cluster secret named {{ include "mysql-cluster.secretName" . }}.

For example in the deployment.yaml:

  replicas: {{ .Values.replicaCount }}
        - name: {{ .Chart.Name }}
            - name: DB_CONNECT_URL
                  name: {{ include "mysql-cluster.secretName" . }}
                  key: DB_CONNECT_URL

Now just modify your app to connect to the DSN that is provided into DB_CONNECT_URL environment variable.

See Also

MySQL Operator Recurrent Backups

MySQL operator provides effortless recurrent backups while keeping the cluster highly available.

The MySQL Operator Upgrades

The steps to make in order to migrate the operator to a newer version of the MySQL operator.