Red Hat OpenShift is a popular enterprise Kubernetes application platform. Openshift has been traditionally considered a platform for stateless applications. However, many developers are exploring the possibility of running stateful workloads, such as MySQL, on OpenShift. If you are considering extending OpenShift for stateful workloads, this tutorial will help you experiment on your existing OpenShift environment by providing step-by-step instructions.
Deploy MySQL on OpenShift Using Helm
In this tutorial, we will deploy a MySQL database on OpenShift using Helm with a single command, load data in the database, and register the MySQL Helm release as an application with ROBIN Storage.
Before you begin this tutorial, install ROBIN Storage on your existing OpenShift cluster.
After you have installed ROBIN, let us install the MySQL client as the first step, so that we can use the MySQL database once deployed.
Let us now confirm that OpenShift cluster is up and running.
You should see an output similar to below, with the list of nodes and their status as “Ready”.
Let us confirm that ROBIN is up and running. Run the following command to verify that ROBIN Storage is ready.
Let us now set up helm. ROBIN has helper utilities to initialize helm.
Let us now create a MySQL database using Helm and ROBIN Storage. The following command will install MySQL. We are setting the storageClass to robin-0-3 to benefit from the data management capabilities that ROBIN Storage brings.
Run the following command to verify our database called “movies” is deployed and all relevant Kubernetes resources are ready.
You should be able to see an output showing the status of your MySQL database.
You would also want to make sure MySQL database services are running before proceeding further. Run the following command to verify the services are running.
Now that we know the MySQL services are up and running, let us get the Service IP address of our database.
Let us now get the Password of our MySQL database from Kubernetes Secret.
Adding data to the MySQL database
We’ll use movie data to load data into our MySQL database. Let’s create a database “testdb” and connect to this “testdb”.
For the purpose of this tutorial, let us create a table named “movies”.
To perform various operations, we need some sample data. Let us add 9 movies to the “movies” table.
Let us verify the data was added to the “movies” table by running the following command.
You should see an output with the “movies” table and the nine rows in it as follows:
We now have a MySQL database with a table and some sample data. Now, let’s take a look at the data management capabilities ROBIN brings, such as taking snapshots, making clones, and creating backups.
Registering the MySQL Helm release as an application
To benefit from the data management capabilities, we’ll register our MySQL database with ROBIN. Doing so will let ROBIN map and track all resources associated with the Helm release for this MySQL database.
Let us first get the ‘robin’ client utility and set it up to work with this OpenShift cluster.
To get the link to download robin client run the following command:
You should see an output similar to below:
Find the field ‘Get _ Robin _ Client’ and run the corresponding command to get the ROBIN client.
In the same output above notice the field ‘Master _ Ip’ and use it to set up your ROBIN client to work with your OpenShift cluster, by running the following command.
Now you can register the Helm release as an application with ROBIN. Doing so will let ROBIN map and track all resources associated with the Helm release for this MySQL database. To register the Helm release as an application, run the following command:
Let us now verify that ROBIN is tracking our MySQL Helm release as a single entity (app).
You should see an output similar to this:
We have successfully registered our Helm release as an app called “movies”.
This concludes the Deploy MySQL on OpenShift tutorial. Now that we have deployed the MySQL database, loaded data, and registered the MySQL Helm release with ROBIN, we can create a MySQL database snapshot and create a MySQL clone including app plus data.