Kubernetes Tutorial: How to Failover MySQL on Google Kubernetes Engine (GKE)

This tutorial is a walk-through of how to failover MySQL on Google Kubernetes Engine (GKE) by Certified Kubernetes Administrator (CKA) and Application Developer (CKAD) Janakiram MSV.

TRANSCRIPT:

Janakiram MSV: Hi. In this video, I’m going to demonstrate how to failover a production MySQL cluster running on GKE and Portworx. So we have an environment that’s already running a single MySQL instance as a Kubernetes deployment, and because we set up the replication factor as three, it’s automatically configured to be redundant and highly available. So we’re going to take advantage of this concept and perform a simulated failover on our production MySQL cluster. So let’s first take a look at what’s available. So we have a MySQL pod that’s running as a part of the deployment. It is essentially a replica set, and if you have been following the previous videos, we configured this as a one replica set of a deployment and this is backed by a PVC that’s pointing to a Portworx storage cluster. Now, our goal is to simulate a failure and then perform a graceful failover with minimal or no downtime. So let’s get started.

So we start this by grabbing the name of the pod that we have just seen. So I’m going to store that in this environment variable, so when we look at this pod, it points us to the MySQL pod name. Then we are going to invoke the MySQL shell. So this is going to drop us right inside the MySQL environment within the pod. Alright, so now we are within the MySQL environment and we’re going to create a sample database called classicmodels, and this is going to create a sample table with a set of columns. Oops, I need to first make sure that we are using this database and then we can create the tables.

Alright. So now we have a table called Offices and let’s go ahead and populate a bunch of rows. So this is going to essentially create some sample data with about seven rows. Let’s query this, so when we actually run this, it points us to the sample data that we just populated and we have about seven rows. Let’s also make sure we are able to perform additional queries, for example, retrieving all the offices within the country, USA. So this is a MySQL database with pre-populated data. Now what we’re going to do is to simulate a node failure, which is a common scenario in production environments. So currently, we have three nodes. What we’re going to do is to get the name of the node that is currently running our MySQL pod and then cordon it off.