Connect Managed Kubernetes to Public Cloud Databases for MySQL
Objective
In this tutorial, we are going to show you how to connect your OVHcloud Managed Kubernetes Service to an OVHcloud Managed MySQL database.
OVHcloud provides services for which you are responsible for their configuration and management. You are therefore responsible for their proper functioning.
This tutorial is designed to help you as much as possible with common tasks. If you are having difficulty performing these actions, please contact a specialized service provider and/or discuss it with our community of users on https://community.ovh.com/en/. OVHcloud can't provide you with technical support in this regard.
Before you begin
This tutorial presupposes that you already have a working OVHcloud Managed Kubernetes cluster, and some basic knowledge of how to operate it. If you want to know more on those topics, please look at the OVHcloud Managed Kubernetes Service Quickstart.
You need to have Helm installed on your workstation and your cluster. Please refer to the How to install Helm on OVHcloud Managed Kubernetes Service tutorial.
Finally, you need to be able to order a database solution in the OVHcloud Control Panel, as explained in our Getting started with Public Cloud Databases guide.
Instructions
Create a MySQL database
Subscribing to the service
Log in to your OVHcloud Control Panel and switch to Public Cloud in the top navigation bar. After selecting your Public Cloud project, click on Databases in the left-hand navigation bar under Storage.
Click on the Create a database instance button. (Create a service if your project already contains databases.)
Step 1: Select MySQL database
Click on the MySQL database and then select the version to install from the drop-down menu. Click Next to continue.

Step 2: Select a solution
In this step, choose an appropriate service plan. You will be able to upgrade the plan after creation.

Please visit the capabilities page for detailed information on each plan's properties.
Click Next to continue.
Step 3: Select a location
Choose the geographical region of the data center in which your database will be hosted.

Click Next to continue.
Step 4: Configure database nodes
You can choose the node model in this step. The initial and maximum numbers of nodes depend on the chosen solution in step 2.

Please visit the capabilities page for detailed information on the hardware resources and other properties of the MySQL database installation.
Take note of the pricing information and click Next to continue.
Step 5: Configure your options
You can name your database in this step.

Step 6: Summary and confirmation
The last section will show a summary of your order as well as the API equivalent of creating this database instance with the OVHcloud API.

Within a few minutes your new database service will be deployed. Messages in the OVHcloud Control Panel will inform you when the database is ready to use.
Your database is ready when cluster status is "Ready", node status is green, and number of users is set to "1 user".

Authorise your OVHcloud Managed Kubernetes cluster
For security reasons the default network configuration doesn't allow any incoming connections. To allow access from your OVHcloud Managed Kubernetes service to the database, cluster nodes IPs have to be authorised. Adding Kubernetes cluster nodes IPs to the authorised list is not recommended on production environnment, and must only be done for testing. Soon, we will write a guide on using vrack, and how to interconnect your various managed services.
Add Kubernetes cluster nodes IPs to the DB authorised list
Get your Kubernetes cluster nodes IP addresses from the Compute / Instances menu on the left.

Following the related documentation on how to authorise the suitable IP addresses, add your Kubernetes cluster node IPs to the authorised list.

Test connection from Kubernetes cluster to MySQL DataBase
An easy and quick way to test the connection is to start a MySQL client inside a pod, and use the Command Line Interface (CLI) to connect to the db.
Start a MySQL client inside a pod
You are now inside the pod you just created on your cluster, you can simply use the MySQL CLI to connect to your managed MySQL database.
The useful parameters are:
-
The db Host, the db Port
- Get them from the "General Information tab"
-
The db Name
- Get it from the "Databases" tab, usually "defaultdb"
-
The db User
- Get it from the "Users" tab, usually "avnadmin"
-
The db Password
- Get it after you reset it.

Now connect to the database with the following command
Setup is done, your Managed MySQL database is fully operational, let's go further and use it with WordPress hosted in Kubernetes.
Installing the WordPress Helm chart
For this tutorial we are using the WordPress Helm chart found on Bitnami repository. The chart is fully configurable, but here we are using the default configuration, with only the minimal set of customization to make it work well on OVHcloud Managed Kubernetes Service.
Pre-requisites
As described in the Installing WordPress on OVHcloud Managed Kubernetes tutorial, remove the default storage class and install the new one.
Customizing your install
By default, the Helm chart installs the WordPress and a MariaDB on the Kubernetes cluster. As you want to use your OVHcloud Managed MySQL database, you need to customize the Helm installation by setting the URL, user and password of your database.
In order to customize your install, without having to leave the simplicity of using Helm and the WordPress Helm chart, you can simply set some of the WordPress chart configurable parameters.
Then you can add it to your helm install command with the --set option (--set param1=value1,param2=value2)
Options to set for accessing the Managed MySQL database are:
This will install the needed elements (a WordPress pod for the webserver with the WordPress PHP code), allocate the persistent volumes and initialize the services. And at the end, it will give you the connection parameters for your new WordPress:
Make sure your MySQL defaultdb database is clean before running the helm install command. If a previous installation is detected, settings such as user and password will not be updated, so the configuration inside of the Kubernetes cluster will not match that of the database.
As the instructions say, you will need to wait a few moments to get the LoadBalancer URL.
You can test if the LoadBalancer is ready using:
After some minutes, you will get the LoadBalancer URL:
Then you can follow the instructions to get the Admin URL:
And putting the URL in your browser will take you to the new blog:

You can also use the instructions given by the helm install command to get the default username and password for your blog.

You now have a working WordPress on your OVHcloud Managed Kubernetes Service, storing data on your OVHcloud Managed MySQL, congratulations!
Cleaning up
To clean up your cluster, simply use Helm to delete your WordPress blog.
It will delete your WordPress and its associated resources from your cluster:
We want your feedback!
We would love to help answer questions and appreciate any feedback you may have.
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.
Are you on Discord? Connect to our channel at https://discord.gg/ovhcloud and interact directly with the team that builds our databases service!