Learn how to connect your OVHcloud Managed Kubernetes Service to an OVHcloud Managed MySQL® database.
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. OVHcloud cannot 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 about 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 Cloud Databases guide.
Instructions
Create a MySQL® database
Subscribing to the service
Please follow the steps of our Databases & Analytics - Getting started guide while ensuring that you select the MySQL® database in the initial step.
Authorize your OVHcloud Managed Kubernetes cluster
NOTE: 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 authorized. Adding Kubernetes cluster nodes' IPs to the authorized list is not recommended in production environments, 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-authorized list
Get your Kubernetes cluster nodes' IP addresses by selecting Instances under Compute in the menu on the left.
Following the related documentation on how to authorize the suitable IP addresses, add your Kubernetes cluster node IPs to the authorized 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 MySQ®L database.
The useful parameters are:
-
The db Host, the db Port
- Get them from the Dashboard 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, and 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 in the Bitnami repository. The chart is fully configurable, but here we are using the default configuration, with only the minimal set of customizations 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.
To customize your installation, 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:
NOTE: 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 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:
Go further
For more information and tutorials, please see our other Managed Databases & Analytics or Platform as a Service guides. You can also explore the guides for other OVHcloud products and services.
OVHcloud Managed Databases and Analytics:
- Grafana® is a registered trademark of Grafana Labs and is used with the permission of Grafana Labs. OVH SAS and its subsidiaries are not affiliated with or endorsed by Grafana Labs.
- Kafka® is a registered trademark of The Apache Software Foundation and has been licensed for use by OVHcloud, who has no affiliation with and is not endorsed by The Apache Software Foundation.
- MongoDB® is a registered trademark of MongoDB, Inc.
- MySQL® is a registered trademark of Oracle and/or its affiliates.
- PostgreSQL® is a registered trademark of the PostgreSQL Community Association of Canada.