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.
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
Let's check to make sure our InnoDB Cluster is up and running
Let's check to make sure our InnoDB Cluster PODS are up and running
Install MySQL Shell
Installation of the MySQL Shell is very straight forward
- yum install mysql-shell
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
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
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
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
Now let's change back to SQL mode in mysqlsh.
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.
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
The new blog database is now visible.
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
We will do the same thing with cluster node mycluster-2
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
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:
Comments