How to Deploy and Manage MySQL on GKE using Helm

In this tutorial, we will deploy a MySQL database on Google Kubernetes Engine (GKE) using Helm and load data in the database. Before you start this tutorial, make sure you have installed ROBIN Storage on GKE.

Continuing on the ROBIN installation tutorial, let us install the MySQL client as the first step so that we can use MySQL once deployed. Run the following command in the cloud shell.

yum install -y mysql –override

Deploy MySQL Database on GKE using Helm

Let us create a MySQL database using Helm and ROBIN Storage. In the Cloud Shell run the following command. This command will install MySQL in Master/Slave configuration mode. We are setting the storageClass to robin-0-3 to benefit from data management capabilities ROBIN Storage brings.

helm install stable/mysql --name films --set
persistence.storageClass=robin-0-3 --set persistence.size=2Gi
--set mysqlDatabase=testdb --tls --tiller-namespace default

Before proceeding, let’s make sure all necessary workloads (pods) are running properly. Click on the “Workloads” tab on the left hand panel, and wait for the status of all workloads to be shown as ”OK” with a green check next to them.

Let’s confirm that our Database is deployed and all relevant Kubernetes resources are ready.

helm list -c films --tls --tiller-namespace default

You should now see the following output showing the status of your MySQL database.

Now get the Service IP address of our MySQL database.

export IP_ADDRESS=$(kubectl get service films-mysql -o jsonpath={.spec.clusterIP})

Get Password of our MySQL database from Kubernetes Secret

export MySQL_PASSWORD=$(kubectl get secret films-mysql-o 
jsonpath="{.data.mysql-root-password}" | base64 --decode;)

Adding data to the MySQL database

We’ll use movie data to load data into our MySQL database. Let’s create a table named “movies”.

mysql -h $IP_ADDRESS -u root -p$MySQL_PASSWORD testdb -e
"CREATE TABLE movies (movieid TEXT, year INT, title TEXT, genre TEXT)"

Let’s add 9 movies to the “movies” table.

mysql -h $IP_ADDRESS -u root -p$MySQL_PASSWORD testdb -e “INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0360556’, 2018, ‘Fahrenheit 451’, ‘Drama’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0365545’, 2018, ‘Nappily Ever After’, ‘Comedy’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0427543’, 2018, ‘A Million Little Pieces’, ‘Drama’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0432010’, 2018, ‘The Queen of Sheba Meets the Atom Man’, ‘Comedy’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0825334’, 2018, ‘Caravaggio and My Mother the Pope’, ‘Comedy’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0859635’, 2018, ‘Super Troopers 2’, ‘Comedy’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0862930’, 2018, ‘Dukun’, ‘Horror’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0891581’, 2018, ‘RxCannabis: A Freedom Tale’, ‘Documentary’);INSERT INTO movies (movieid, year, title, genre) VALUES (‘tt0933876’, 2018, ‘June 9’, ‘Horror’)”

To see the movies added to the “movies” table, run the following command.

mysql -h $IP_ADDRESS -u root -p$MySQL_PASSWORD testdb -e “SELECT * from movies”

You should see an output similar to the following:

Advanced Data Management for Kubernetes - Deploy MariaDB on GKE using Helm | Get ROBIN Storage on Google Cloud Marketplace for Stateful workloads

We have now deployed a MySQL database on GKE with a table and some sample data.

To benefit from data management capabilities ROBIN brings, such as taking snapshots, making clones, and creating backups, we have to register this MySQL Helm release as an application with ROBIN.

Registering the MySQL Helm release as an application

Registering this MySQL Helm release as an application will enable 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.

robin app register myfilms –app helm/films

Let us verify ROBIN is now tracking our MySQL Helm release as a single entity (app).

robin app list –name myfilms

You should see an output similar to this.

Advanced Data Management for Kubernetes - Deploy MariaDB on GKE using Helm | Get ROBIN Storage on Google Cloud Marketplace for Stateful workloads

We have successfully registered our Helm release as an app called “myfilms”.

This concludes the Deploy MySQL on GKE 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.

mm

Author Ankur Desai, Director Products

More posts by Ankur Desai, Director Products