For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt, and this page is available as Markdown at https://docs.us.ovhcloud.com/en/public-cloud/databases/mysql-tutorial-connect-managed-kubernetes-service.md.
  • English

MySQL® - Tutorial - Connect to your Managed Kubernetes Service

View as Markdown

Learn how to connect your OVHcloud Managed Kubernetes Service to an OVHcloud Managed MySQL® database.

Warning

NOTE: 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. 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

Warning

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.

MySQL tutorial connect managed Kubernetes service - step 12

 

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

Manager database - MySQL tutorial connect managed Kubernetes service - step 2

 

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

kubectl run mysql-client --image=mysql:8 -it --rm --restart=Never -- /bin/bash

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

    Manager database - MySQL tutorial connect managed Kubernetes service

 

Now connect to the database with the following command:

mysql -uavnadmin -pxxxxxxxxxxxxxx -hmysql-xxxxxxxx-xxxxxxxxx.database.cloud.ovh.us -P20184 defaultdb
root@mysql-client:/# mysql -uavnadmin -pxxxxxxxxxxxxxx -hmysql-xxxxxxxx-xxxxxxxxx.database.cloud.ovh.us -P20156 defaultdb
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3603
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

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.

kubectl delete storageclasses.storage.k8s.io csi-cinder-high-speed

kubectl apply -f https://raw.githubusercontent.com/ovh/docs/develop/pages/public_cloud/containers_orchestration/managed_kubernetes/fix-persistent-volumes-permissions/files/fixed-cinder-high-speed-storage-class.yaml

 

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:

mariadb.enabled=false
externalDatabase.host=mysql-abcdefgh-ijklmnopq.database.cloud.ovh.us
externalDatabase.user=avnadmin
externalDatabase.password=mYStrongPasswOrdHere
externalDatabase.database=defaultdb
externalDatabase.port=13660

 

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:

$ helm install my-wordpress bitnami/wordpress --set allowOverrideNone=true,mariadb.enabled=false,externalDatabase.host=mysql-abcdefgh-ijklmnopq.database.cloud.ovh.us,externalDatabase.user=avnadmin,externalDatabase.password=mYStrongPasswOrdHere,externalDatabase.database=defaultdb,externalDatabase.port=20156
NAME: my-wordpress
LAST DEPLOYED: Thu Dec 23 15:49:33 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: wordpress
CHART VERSION: 12.2.7
APP VERSION: 5.8.2

** Please be patient while the chart is being deployed **

Your WordPress site can be accessed through the following DNS name from within your cluster:

    my-wordpress.default.svc.cluster.local (port 80)

To access your WordPress site from outside the cluster follow the steps below:

1. Get the WordPress URL by running these commands:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w my-wordpress'

   export SERVICE_IP=$(kubectl get svc --namespace default my-wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
   echo "WordPress URL: http://$SERVICE_IP/"
   echo "WordPress Admin URL: http://$SERVICE_IP/admin"

2. Open a browser and access WordPress using the obtained URL.  

3. Login with the following credentials below to see your blog:

  echo Username: user
  echo Password: $(kubectl get secret --namespace default my-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)
Warning

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:

kubectl get svc --namespace default -w my-wordpress

 

After some minutes, you will get the LoadBalancer URL:

$ kubectl get svc --namespace default -w my-wordpress
NAME           TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                      AGE
my-wordpress   LoadBalancer   10.3.193.143   135.125.83.116   80:32027/TCP,443:32293/TCP   4m30s
$ export SERVICE_IP=$(kubectl get svc --namespace default my-wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
$ echo "WordPress URL: http://$SERVICE_IP/"
WordPress URL: http://135.125.83.116/
$ echo "WordPress Admin URL: http://$SERVICE_IP/admin"
WordPress Admin URL: http://135.125.83.116/admin

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:

MySQL tutorial connect managed Kubernetes service - step 11

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

$ echo Username: user
Username: user
$ echo Password: $(kubectl get secret --namespace default my-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)
Password: GSPSIXwGok

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.

helm uninstall my-wordpress

It will delete your WordPress and its associated resources from your cluster:

$ helm delete my-wordpress
release "my-wordpress" uninstalled

 

Go further

Browse all the Databases guides.

Browse the rest of the OVHcloud US documentation for guides on our other products and services.

Learn more about Managed Databases on the OVHcloud US website.

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.