Creating The Kubernetes Cluster On The Top Of Cloud Using CMD Prompt (AWS EKS)

In this story, I am going to tell you about how to set up your Kubernetes cluster on the top of the AWS cloud and deploy any web app and connect with the SQL server and store data in centralized EFS storage. We also discuss the Farget cluster in this Article.


i. Kubernetes Cluster using AWS EKS.

ii. Integrate EKS with EC2,EBS,LB,EFS.

iii. Deploying WordPress & MySQL on top of it.

iv. Farget Cluster (Serverless Architecture).


You should have some basic knowledge of EC2 instance, EFS storage, Kubernetes, and yml syntax. You should have Aws IAM account with admin power. Open the cmd and login with the AMI account using aws configure cmd and provide the credentials of your IAM account.

Software required:-

i. awscli ( )

ii. eksctl ( )

iii. Kubectl ( )

Note:- Put all this exe file in one folder and Set the path of this folder in the system environment variable.

EKS:- EKS is one of the services of AWS. It is mainly the Kubernetes service. It is a managed service that is fully managed by the AWS guys.

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

Now we 1st configure our AWS.

For configuration provides your credentials and region where you want to launch your cluster. In my case, I am launching in ap-southeast-1(Singapore)

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.

my yml file

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

i.e eksctl create cluster -f cluster.yml

To check the cluster we use eksctl get cluster cmd

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

Now we are here creating one separate namespace for our use. And cmd 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=bhaskar-ns cmd.

To see how many pods are running we use kubectl get pods cmd. Currently, no pods are running because we haven’t launch anyone yet.

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

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> cmd.

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.

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.

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.

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 myweb — 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.

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.

My pvc.yml file

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

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.

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.

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

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.

Every time when you launch any or change anything in the cluster you need to update your Kube config file if the system.

for updating the Kube config file we use aws eks update-kubeconfig — name myCluster cmd. It will update all the new information of the cluster into this file.

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.

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

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.

You see within 1 min your EFS is created.

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.

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

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

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.

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.

deploy-mysql.yaml file
deploy-wordpress.yaml file

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

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.

Click on the write your 1st blog post

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

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

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

B.Tech student and Researcher. Like To Study And Publish Article Related To New Technologies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store