MySQL InnoDB Cluster on AWS using Kubernetes and StatefulSets
byEmmanuel COLUSSI
MySQL InnoDB Cluster on AWS using Kubernetes and StatefulSets
We will resume our infrastructure created in the previous post: Installing Kubernetes on AWS infrastructure with Terraform and kubeadm.
We will add storage to each worker nodes and install OpenEBS on our kubernetes cluster.In this post I won’t detail the OpenEBS installation part, I strongly advise you to see the following posts:
To execute this tutorial you need to set up the infrastructure deployed in this previous post.
We will use a terraform template to create our volumes on each workers instances.
Architecture
We have 4 VMs :
master-node-0
worker-node-0
worker-node-1
worker-node-2
Prerequisites
Before you get started, you’ll need to have these things:
Terraform > 0.13.x
kubectl installed on the compute that hosts terraform
We are going to add two volumes of type EBS (Elastic Block Store) of 20 Gb to each of our Worker instances .
And we will deploy our OpenEBS afterwards which will use these volumes.
Provisioning EBS volume and attaching it to a Terraform EC2 worker instance.
Elastic Block Store are disk volumes which can be attached to EC2 instances.
EBS volumes exist independently, meaning their lifecycle is not dependent on the EC2 instance they are attached to.
Step 1 : get id for each worker instance : run run the following commands :
Modify the file variables.tf in the directory : addstorage
You should modify the worker_instance_id entry with the id values of your instances and the worker_zone entry with your working zone.
Usage
Create EBS volume and attaching it to worker instance
Tear down the whole Terraform plan with :
In a few seconds your volumes are created
Use the lsblk (on each worker nodes) to view any volumes that were mapped at launch but not formatted and mounted.
we have our two 20 Gb disks (nvme1n1nvme2n1) attached to our instance.
Now let’s install our distributed storage OpenEBS.
We will use the storage class sc-cstor-csi-student1 and set it as default storage class
Mark a StorageClass as default:
Verify that your chosen StorageClass is default:
Installing the MySQL InnoDB Cluster
For the deployment of our MYSQL cluster we will use the MYSQL operator for kubernetes.
The MYSQL Operator for Kubernetes is an Operator for Kubernetes managing MySQL InnoDB Cluster setups inside a Kubernetes Cluster.
The MySQL Operator manages the full lifecycle with setup and maintenance including automation of upgrades and backup.
The MySQL Operator for Kubernetes currently is in a preview state. DO NOT USE IN PRODUCTION.
Installing the MySQL Operator
We lets create a unique namespace for the mysql-operator
we will also create a namespace for our MYSQL cluster
The MYSQL Operator can be installed using kubectl:
Verify the operator is running :
Create a secret containing credentials for a MySQL root user
We will now create our InnoDB cluster with 1 router and 3 instances
ec2-user@ip-10-1-0-87:~> kubectl get service mycluster01
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mycluster01 ClusterIP 10.105.48.54 6446/TCP,6448/TCP,6447/TCP,6449/TCP 3m20s
ec2-user@ip-10-1-0-87:~> kubectl get innodbcluster
NAME STATUS ONLINE INSTANCES ROUTERS AGE
mycluster01 ONLINE 3 3 1 3m37s
ec2-user@ip-10-1-0-87:~> kubectl get pods
NAME READY STATUS RESTARTS AGE
mycluster01-0 2/2 Running 0 3m51s
mycluster01-1 2/2 Running 0 2m44s
mycluster01-2 2/2 Running 0 86s
mycluster01-router-5cdvr 1/1 Running 0 2m44s
kubectl get cstorvolume –all-namespaces
NAMESPACE NAME CAPACITY STATUS AGE
openebs pvc-36754aff-5d7c-42e9-86d5-6045dbbb29b9 2Gi Init 35m
openebs pvc-c52e0f7c-9594-4175-b217-f54f1065c9da 1Gi Healthy 86m
Create a PVCs yaml using above created StorageClass name
First we are creating three persistent volumes (mysqldata01-mysqldata03) for our InnoDB Cluster nodes. We are specifying that this volume can only be accessed by one node (ReadWriteOnce) We are also specifying that we will use our StorageClass for storage. More information on PV here.