Getting Started with MySQL Shell , The Oracle MySQL Kubernetes Operator and Portworx

Overview

In this blog I will show you how to use the MySQL Shell to manage and create a clustered database on an InnoDB MySQL cluster which has been provisioned using the Oracle MySQL Kubernetes Operator, and Portworx to provide the data management layer and persistent volumes

The benefit of using Portworx is we can create custom storage classes defining storage attributes such as replication factors, snapshot policies, dynamic PVC creation for stateful applications and intelligent pod placement.

This blog will not go into the details on how to setup Kubernetes, Portworx or the Operator, my Colleague Ron Ekins has written an excellent blog on the installation process.

https://ronekins.com/2021/08/31/getting-started-with-the-oracle-mysql-kubernetes-operator-and-portworx/

Environment

* Kubernetes 1.21
* Portworx 2.8
* MySQL operator installed https://github.com/mysql/mysql-operator
* MySQL Shell

Let's check to make sure our operator is up and running

Screen Shot 2021-10-13 at 12 39 57 pm

Let's check to make sure our InnoDB Cluster is up and running

Screen Shot 2021-10-13 at 12 40 42 pm

Let's check to make sure our InnoDB Cluster PODS are up and running

Screen Shot 2021-10-13 at 11 50 59 am

Install MySQL Shell

Installation of the MySQL Shell is very straight forward

  • yum install mysql-shell

Screen Shot 2021-10-13 at 12 41 28 pm

Note: because I don't have a load balancer on my kubernetes environment, I will be using kubernetes port forwarding to connect to the MySQL PODS from the K8 Master node connecting to port 6446

Screen Shot 2021-10-13 at 12 45 17 pm

Lets get the IP addresses of the cluster PODS we want to connect to.

root@px-centk8s01 ~]# kubectl get pods -o wide
10.244.1.44 | 10.244.1.45 | 10.244.1.46

Screen Shot 2021-10-13 at 12 53 05 pm

Connecting to the localhost using mysqlsh "mysqlsh chrisb@localhost:6446 --sql" I have already created a user called "chris" as an admin user on the cluster nodes In this example I am connecting to the mysql cluster pod running on port 6446 as the user chris, notice the SQL prompt - mysqlsh allows you to connect in SQL mode or JS ( java script ) mode

Screen Shot 2021-10-13 at 12 47 30 pm

Lets change to JS mode ( SQL> \js ) and check the cluster status, we can see the three cluster nodes with mycluster-0 as the primary node

Screen Shot 2021-10-13 at 2 00 42 pm

Now let's change back to SQL mode in mysqlsh.

Screen Shot 2021-10-13 at 4 13 18 pm

From the SQL prompt we can run any SQL command which you can run from a standard mysql database connection, let's have a look at what databases are configured.

Screen Shot 2021-10-13 at 3 54 18 pm

Let's check which which cluster node we are on, then we will create a new database called blog and confirm all the cluster nodes can see and read the database. We are on the mycluster-0

Screen Shot 2021-10-13 at 4 19 14 pm

The new blog database is now visible.

Screen Shot 2021-10-13 at 4 20 21 pm

Lets now connect to cluster node mycluster-1 "10.244.1.45" and confirm we can see the new blog database, I will switch back to JS mode and connect to each cluster node

Screen Shot 2021-10-13 at 4 22 04 pm

We will do the same thing with cluster node mycluster-2

Screen Shot 2021-10-13 at 4 23 12 pm

Now because cluster nodes 1 and 2 are read-only nodes we cannot create a database or add data to a table as we can see from attempting to create a new database called blog2 on mycluster-2

Screen Shot 2021-10-13 at 4 24 04 pm


Summary


In this blog we have seen how we can install MySQl Shell to manage a MySQL cluster installed using the Oracle MySQL Kubernetes Operator, while the storage is being managed by Portworx.


To learn how to install the MySQL kubernetes Operator visit:


https://ronekins.com/2021/08/31/getting-started-with-the-oracle-mysql-kubernetes-operator-and-portworx/


Comments

Popular posts from this blog

Oracle Containers on Kubernetes and Pure Service Orchestrator

SQL Server container with Pure Storage Docker volumes

Using Portainer to Manage and Deploy Oracle Containers with Pure Storage