Learn how to connect your OVHcloud Managed Kubernetes Service to an OVHcloud Managed MySQL database.
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
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 Databases & Analytics.
Click on the Create a database instance
button (click 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.
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.
Step 3: Select a region
Choose the geographical region of the data center in which your database will be hosted.
Step 4: Configure database nodes
You can choose the node type in this step. The initial and maximum numbers of nodes depend on the chosen solution in step 2. You can also add additional storage.
Please visit the capabilities page for detailed information on the hardware resources and other properties of the MySQL database installation.
Please take note of the pricing information.
Step 5: Configure your options
Define your network type.
Configuring a private network (optional)
If you already have a private subnet available, check the box Private and select it from the drop-down menu. Note that this option might not be available for the selected service type.
You can be forwarded to create a private network or subnet by clicking on the respective links. You will have to start the database order process anew in that case.
Please follow this guide for detailed instructions.
Step 6: Summary and confirmation
A side panel will show a summary of your order. You can view the API (OVHcloud API) and Terraform equivalents as well.
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 the number of users is set to "1 user".
Authorize your OVHcloud Managed Kubernetes cluster
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
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 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:
mysql -uavnadmin -pxxxxxxxxxxxxxx -hmysql-xxxxxxxx-xxxxxxxxx.database.cloud.ovh.us -P20156 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 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.
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=20156
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)
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
Then you can follow the instructions to get the Admin URL:
$ 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
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.
$ 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
For more information and tutorials, please see our other Cloud Databases support guides or explore the guides for other OVHcloud products and services.