How to Deploy MariaDB on GKE using Helm

In this tutorial, we will deploy a MariaDB 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 MariaDB once deployed. Run the following command in the cloud shell.

Deploy MariaDB Database on GKE using Helm

Let us create a MariaDB database using Helm and ROBIN Storage. In the Cloud Shell run the following command. This command will install MariaDB 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/mariadb --name films --set master.persistence.storageClass=robin-0-3 --set master.persistence.size=2Gi --set slave.persistence.storageClass=robin-0-3 --set slave.persistence.size=2Gi --set db.name=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 be able to see an output showing the status of your MariaDB database.

 

Get Service IP address of our MariaDB database.

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

Get Password of our MariaDB database from Kubernetes Secret

export MARIADB_PASSWORD=$(kubectl get secret films-mariadb -o jsonpath=”{.data.mariadb-root-password}” | base64 –decode;)

Adding data to the MariaDB database

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

mysql -h $IP_ADDRESS -u root -p$MARIADB_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$MARIADB_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$MARIADB_PASSWORD testdb -e "SELECT * from movies"
 

You should see an output similar to the following:

We have now deployed a MariaDB 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 MariaDB Helm release as an application with ROBIN.

Registering the MariaDB Helm release as an application

Registering this MariaDB Helm release as an application will enable ROBIN map and track all resources associated with the Helm release for this MariaDB 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 MariaDB Helm release as a single entity (app).

robin app list --name myfilms
 

You should see an output similar to this.

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

This concludes the Deploy MariaDB on GKE tutorial. Now that we have deployed the MariaDB database, loaded data, and registered the MariaDB Helm release with ROBIN, we can create a MariaDB database snapshot and create a MariaDB clone including app plus data.

 

Recommended Posts