AWS EKS - Kubernetes Cluster On The Top Of AWS Cloud

AWS EKS - Kubernetes Cluster On The Top Of AWS Cloud

In this Article I am going to explain you about how to setup EKS Cluster on AWS Cloud and deploy application on the top of POD's and connect with the MYSQL server and store data in centralized EFS storage. We also discuss the Farget cluster in this Article.

Before this you should have some basic understanding about EC2 instance, EFS storage, Kubernetes, and yml Format. You should have Aws IAM account with admin power.

First login with the AMI account using " aws configure" on cmd and provide the credentials of your IAM account and also required awscli , eksctl binary installed.

eksctl is a simple CLI tool for creating clusters on EKS ...

You should also required kubectl command line tool for control Kubernetes clusters.

EKS : EKS stands for Elastic Kubernetes Service, which is an Amazon offering that helps in running the Kubernetes on AWS without requiring the user to maintain their own Kubernetes control plane. It is a fully managed service by Amazon.

No alt text provided for this image

1. Here we create the simple cluster and deploy our wordpress application over it. For this, we use the EBS and ELB services of AWS.

Now we 1st configure our AWS. For configuration we provides credentials and region where we want to launch our cluster. In my case, I am launching in ap-southeast-1(Singapore)

No alt text provided for this image

After configuration now we create the cluster where we launch our Kubernetes service. For launching the Kubernetes service we required one (.yml) file which contains the information of cluster.

No alt text provided for this image

Now launching the cluster we use " eksctl create cluster -f <filename.yml> " cmd. It takes approx 10 min to setup. In my case, my file name is eksfile.yml

eksctl create cluster -f cluster.yml

No alt text provided for this image

To check the cluster we use eksctl get cluster cmd

No alt text provided for this image

To check the pods of the cluster use kubectl get nodes cmd.

No alt text provided for this image

2. Now we are here creating one namespace for our purpose

Commad for creating a namespace is "kubectl create namespace <namespace_name>"

To check the create namespace we use kubectl get ns cmd.

To use the newly created namespace we use kubectl config set-context — current — namespace=suraj-ns "

To check pods is running or not we use kubectl get pods cmd. In my case, it is working fine. Here we use deployment because deployment is very much fault tolerance. If due to any reason your deployment fails/crash it automatically launches new for you.

No alt text provided for this image

To see where your cluster is running we use kubectl cluster-info cmd. This cmd shows the location where your master is running.

No alt text provided for this image


Now we are going to launch/create one deployment where we put our PHP/HTML website. For creating the deployment we use kubectl create deployment <deployment_name> — image=<image_name> command.

To check our pod is exposed or not we use kubectl get services cmd. Here we see one Loadbalancer is come up. It means our pods are exposed.

No alt text provided for this image

Here our pod is running in private IP and we need to expose it then we connect to it from the outside world. For providing the connection form outside world we use the concept of NAT(Nating). This connection is client-facing. Behind the scene, it will provide one load balancer which connects to the public world. If any request comes from the outside world it automatically redirects to one of the launched pods.

No alt text provided for this image

If you want to scale your pods means you want to create the replica of this pod then. 1st we need to know the desire means how much pods we want to create. In my case my desire is 4 then we run the cmd kubectl scale deployment webapp — replica=4. It will create 3 more replicas for you because 1 replica is already there in running state.

Now use the load balancer address and put it into the web browser you will get the deployed web page.

No alt text provided for this image


Above we use load balancer so if whenever you connect you will get the different IP due to the load balancer. Because every time load balancer sending the traffic to different pods to manage the load.

In pods, the storage we use is a non-persistent type. It means everything we store inside will delete if any failure occurs. To make the storage permanent means persistent we mount one volume and this volume is typically known as EBS in aws. After mounting to the centralized storage out data become permanent.

Here I am creating one .yml file for PVC (persistent volume claim). This is a service which is connected to the client-side and if any request is generated from the client then it will contact the PV(persistent volume) and this PV send a request to the storage class and storage class is so intelligent program that knows how to provide the storage from different storage groups. Here is my case storage class contact with EBS for storage.

No alt text provided for this image

create the PVC we use kubectl create -f mypvc.yml cmd. For confirming PVC is created or not we use kubectl get pvc cmd.

No alt text provided for this image

After creating the PVC we need to go to our deployment and update deployment because without updating the deployment PV will not create and also update the mount path. For editing the deployment we use kubectl edit deploy myweb cmd. I use myweb because my deployment name is myweb.

No alt text provided for this image

put this code in the spec section of the deployment with proper indentation. and save it.

To check the PV is created or not. For this, we use kubectl get pv. After that our storage becomes permanent.

To destroy the cluster we use eksctl delete cluster -f cluster.yml cmd.

2. Now Here we create the mix node group using the spot instance and deploy the WordPress and MySQL over it. For this, the services we use are ELB, EFS, EC2.

Now I am creating a 1 yml file that contains the instruction of the mixed node group which we are going to execute. Also, attach 1 private key for future login into the instances. In my case my key name is myKey.

No alt text provided for this image

Here I am laughing 2 spot instance t3.small and t3.medium. Execute this file using "kubectl create cluster -f kubecluster.yml ". It takes 10 min to setup.

No alt text provided for this image

Now to check instance is launched or not we go to the Amazon console and check the ec2 instance dashboard. You find your instance is launched. also to check cloud formation is launched or not we go to the Amazon console and check the ec2 instance dashboard. You find your instance is launched.

No alt text provided for this image


No alt text provided for this image

Behind the scene, Cloud Formation created all the EKS cluster you can see below.

No alt text provided for this image

Now we are login into all the ec2 instances with root account and install one software using yum install amazon-efs-utils cmd. Do this step for all the instances which we launch. For login, we use the above-highlighted cdm.

Now we are creating one EFS here. We create EFS Because EFS is centralized storage and whenever we do any changes from any region will also reflect in other associated regions. So if any client changes something from region 1a and if he/she again login with 1b region then he/she will get the same edited file.

No alt text provided for this image

Now click on the EFS option. One window will open like this. As shown below.

No alt text provided for this image

Now select the create file system option. and select the VPC and change from default to highlighted VPC and also change the security group from default to clusterShareNodeSecurityGroup. It will allow the nodes to ping each other and also share the file internally.

No alt text provided for this image

Now within 1 min your EFS is created.

Then Copy the file system-id. Now we are going to create a 1 yml file that helps us to provision this efs into our cluster. Paste the copy system-id into the values section. As I do below. Also, do changes in the server part of your yml file.

No alt text provided for this image


Now time to provision our efs into our cluster. For this, we use " kubectl create -f <provisioner_name>.yml ".

Now to check the provisioned is working or not we above highlighted cmd. In my case, it is working fine.

Now we create one RBAC which helps us to secure our namespace. From the outside world

To execute this yml file we again use kubectl create -f file_name.yml

No alt text provided for this image

To execute this yml file we again use kubectl create -f file_name.yml

Now we create the 1 storage class efs. This storage class contacts the efs to provide the storage. And we create 1 pvc which creates PV and this PV contact the storage class and storage class provide the storage from efs.

No alt text provided for this image

It will create persistent storage of 20–20 GB in EFS.

After doing all the setup we are ready to launch our web app and with MySQL database. For launching, we will place all the file in one folder and configure one kustomization(kustomization is one feature of Kubernetes which execute all the files in a single go the only challenge is all file is in the same folder and kustamiztion contain the name of the file which is executed in a single go.) file which launches both my SQL and WordPress.

No alt text provided for this image


Then Created Secret for mysql pod

No alt text provided for this image


NOw we Create Wordpress pod

No alt text provided for this image

Now We create secret for wordpress

No alt text provided for this image

Now in kubernets we have one feature called Kustomization .

No alt text provided for this image

for executing the kustomization we use kubectl create -k . (here dot represents the current folder) command.


Now we check everything is working fine or not. To do this we use kubectl get all cmd

copy the URL of the load balancer and put it into the web browser.

No alt text provided for this image


copy the address and put it into the web browser now you see your published blog like this.

No alt text provided for this image


3. Now we are going to launch one Farget cluster.

No alt text provided for this image


we create the farget cluster by using kubectl create -f myfarget.yml command.

Hope You Liked It!!

If any query feel free DM me.


要查看或添加评论,请登录

Suraj S.的更多文章

社区洞察

其他会员也浏览了