Integrate in Helm charts

How to integrate the Bitpoke operator for MySQL 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 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, including the master node. 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>) but DO NOT use just the service (eg. mysql.<namespace>) as it contains all nodes from all clusters in the namespace.

Using Helm

We provide a Helm chart for easy deployment of a MySQL cluster alongside your application. It can be found in the bitpoke helm charts repository and used stand alone or added as a dependency. See below 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.5.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 values.yaml 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 points to the DB_CONNECT_URL field from cluster secret. To get the secret name you can use the following template {{ 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.