Deploy MySQL instance on Amazon EKS cluster
The purpose of this tutorial is a walk-through of the steps involved in deploying and managing a highly available MySQL database on Amazon EKS.
Prerequisites
Before you get started, you’ll need to have these things:
- Terraform > 0.13.x
- kubectl installed on the compute that hosts terraform
- An AWS account with the IAM permissions
- AWS CLI : the AWS CLI Documentation
- AWS IAM Authenticator : the AWS IAM Authenticator Documentation
- EKS cluster running
- A default storage class
- MySQL client
Initial setup
For the creation of the EKS cluster, see the previous post:Create Amazon EKS cluster using Terraform
Clone the repository and install the dependencies:
Usage
Create a MS SQL Server instance:
If you use the terraform apply command without parameters the default values will be those defined in the variables.tf file.
This will do the following :
- create a namespace
- create of the secret object for the password sa for the MS SQL Server instance
- the password is base64 encoded, in this example the password is : Bench123
- create a PVC : Persistant Volume Claim
- create a deployment object for MySQL Server : create a MySQL Server instance
- create a service object for MySQL Server instance:
Tear down the whole Terraform plan with :
Resources can be destroyed using the terraform destroy command, which is similar to terraform apply but it behaves as if all of the resources have been removed from the configuration.
Remote control
Check if your MySQL instance works:
To access the MySQL Server Instance :
Now that we are inside the shell, we can populate create a sample database and table.
Step1 : get a sample database
Step2 : copy The Employees database files in POD :
Verified that the files are copied correctly :
Step3 : run the SQL scripts for creating the employee data base and loading the data
Let’s run a few queries on the table.
if you have installed an AWS Load Balancer Controller and assigned the MySQL service you can connect to your instance directly using the external IP address.
More information on this link for the installation of a AWS Load Balancer Controller.
Get the external IP address :
The external IP address is :
aa6ba6af1452d4e2194d3eff8e2836f1-899797895.us-east-1.elb.amazonaws.com
You can access the MySQL Server instance with your favorite tool like MySQLWorkbench :
Conclusion
MySQL can easily be deployed on Amazon EKS to run stateful workloads in production. Terraform makes it easy to manage Kubernetes clusters and Kubernetes resources effectively. It gives organizations the opportunity to work with infrastructure-as-code, management of platforms, and also the opportunity to create modules for self-service infrastructure. Terraform Kubernetes provider gives organizations all the required tools necessary to manage Kubernetes clusters in the environment.
Resources :
A sample database with an integrated test suite, used to test your applications and database servers
AWS IAM Authenticator for Kubernetes