Creating EKS-cluster and deploying WordPress and MySQL pods and integrating them with EFS, ELB services using Command-line interface
Amazon EKS is a managed service that helps make it easier to run Kubernetes on AWS. Through EKS, organizations can run Kubernetes without installing and operating a Kubernetes control plane or worker nodes. Simply put, EKS is a managed containers-as-a-service (CaaS) that drastically simplifies Kubernetes deployment on AWS.
In this article, I will be creating an EKS cluster using the eksctl program using the Command-line interface(CLI). Afterward, I will deploy WordPress with MySQL database and integrate them with EFS service to provide persistent storage to the cluster and ELB for load-balancing the pods.
Firstly we have to connect with the AWS and we have 3 ways for it:
- WebUI
- CLI(Command Line Interface)
- SDK(Software Development Kit)
I will be using CLI because it helps us to solve multiple use-cases.
Before launching the EKS cluster, we should have AWS IAM user account having administrator access and it should be configured in CLI using aws configure command.
I have configured eksctl in my local system and there is no cluster running in my system.
Now, I will be creating an EKS cluster automatically using eksctl command. For this, I have created a cluster.yaml file which contains region-name, no. of instances and instances type we need in our cluster. You will get all my files at my GitHub link given below.
After using this command, we can see EKS cluster is successfully running and is ready to use. It takes approx 20 min to launch eksctl is a powerful program that automatically creates VPC, CloudFormation and other services required to launch our cluster.
Verification using CLI
Verification using WebUI
CloudFormation:
Instances launched:
Now, we will update our configuration file for kubectl program to use the EKS cluster from my local system using the command below.
Now my configuration file is updated.
Now we will set-up EFS which provides a simple, scalable and fully managed NFS file system and mount it to all the instances of our EKS cluster.
EFS configuration:
We need to provide the same security group for EFS that is used by our instances so that it will allow instances to access the EFS server.
Now, my EFS is successfully created.
Now we need to install amazon-efs-utils in all our instances so that our instances could connect to EFS. For this, we will be manually connecting to instances via SSH and install in it using the command given below.
Now we will create a namespace in our EKS cluster and launch all our pods in this namespace.
Now we will create the EFS provisioner using efs_provisioner.yaml file so that StorageClass would connect our EKS cluster to EFS and will change permission for provisioner by creating security called Role Bindingusing rbac.yaml file. We will also create a StorageClass and PVC for WordPress and MySQL pods using storage.yaml file using the command given below.
We can see the new StorageClass and PVC have been created and PV is being dynamically created.
Now we will deploy WordPress and MySQL pods through deploy-wordpress.yaml and deploy-mysql.yaml file respectively. We have also created a service for exposing the WordPress pod and load-balancing it which internally integrates with ELB and does load balancing between the pods. We have created ClusterIP service for MySQL so that it should not have any outside connectivity except WordPress.
But before launching MySQL, we have to create a secret for securing database password.
We can see our deployments, services and pods have been created successfully. Now we can access our website using external IP provided for the WordPress pod.
We can see our WordPress site has launched having persistent data with ELB services.
GitHub Code link: