Deploying App on AWS EKS (Elastic Kubernetes Service )
Hritick Goyal
Data Engineer @ Jio | Immediate Joiner l Serving Notice Period | Microsoft azure data engineer associate DP203
In this blog i will explain how to use amazon eks service to deploy app . First it is good to know what is eks service.
EKS
Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service. Customers such as Intel, Snap, Intuit, GoDaddy, and Autodesk trust EKS to run their most sensitive and mission critical applications because of its security, reliability, and scalability.
This above graph show how popular is this aws service.
I will explain step by step how to use aws eks service.
1. Create aws user account
We have to first create aws user account other than root user as follows
Go to IAM service of aws then click on Users option .After that click on add user.
We have successfully created user account with administrator access.
2. Login to user account
To use aws service we have to login to account of aws .we can login either using webui or cli. In this i am using cli to login .For this we should have aws client command installed in laptop.And if not installed go through this link
First run aws configure command .This command used to login to aws account .After that give account's access key and id which should be copied earlier .
We have login to aws user account successfully.
3. Create Kubernetes Cluster
Now we have to create kubernetes cluster .For this we can use either eks command or eksctl.i am using eksctl command because it gives more features to configure cluster.Amazon eks fully managed master node so we dont need to create this we just need to create slave nodes. For this we can write code to create slave nodes in yml formate as mention below.
So here i give my cluster name as lwcluster in region ap-southeast-2 . I suggest to not to launch cluster in mumbai region.Nodegroup basically means nodes having same resources as i used t2.micro .So basically this code will launch 3 nodes of t2.micro type having nodegroup name as ng1 in south-east-2 region.And since we are configuring our cluster so its kind is ClusterConfig.
To create cluster used eksctl create cluster command
It takes approx 20 to 25 mins to create cluster.
We can see our cluster from webui as
Similarly all the instances created by cluster
4. Update kubectl
Now we will use kubectl command to use this cluster .For accessing this cluster we first need to update kubectl config file for this cluster so that kubectl command can access cluster.
We can create our own namespace also so that we can launch any deployment in that namespace only .For this use below commands
Now to use this namespace to our cluster we have to set this namespace as follow
In this we have set this namespace to current which is basically our clutser.
5. Launch web server in eks
Now we create one deployment to launch web server .For this we either can use command directly or can use code .I used command .
In this i have created one deployment by name web to launch apache-web server by using precreated image from hub.docker.com.
To see all services running.
We can see all info of pod that we launch using deployment by this.
6. Attach PV (persistent volume) to pod
As we know our web-server data is important and to prevent this data from loss after termination of pod we can use pv(persistent volume) . For this we can use code as follow
Here I have created one pvc(persistent volume claim) because pvc is the one to whom pod ask for storage and pvc get storage from pv and pv get it from storage class . Now there is two way for this 1. static 2. dynamic . I have used dynamic way because in this we just need to create pvc only after that pv will create automatically and we also do not need to think about storage size also.
So in this code there will be one pvc create of 10 Gi with name lwpvc1 with access mode read and write .
Now we have to do some configuration in our deployment for this pvc so that deployment can get pv .
When we run kubectl edit deploy command it open this file now we need to add some code in this file.Here I have created one volume with name web-vol1 and get that volume from pvc .after that we need to mount that volume to folder where web-server data store.
7. Public access of Web-server
Now our web-server is ready even if pod get terminate there will be no data loss .But our server is in isolated world to give access of it to public world we need to expose it or say do patting of this .
So I expose my web-server to port 80 by using load balancer type . I used this load balancer because this service has capability to link with aws elb (elastic load balancer ) .Which have capability to give public access as well as to do load balancing of this pod.
We can also launch as many pod as we want by using scaling features of K8s.
I have created total 3 pods .
Finally we can access our web-server running on port 80.
8.Install package manager for kubernetes
For launching app or software on k8s we need one package manager like yum in linux or pip in python that can go and download and install app on behalf of k8s . Such a package manager is Helm.
Helm
Helm helps you manage Kubernetes applications .Helm is made of two components: A server called Tiller, which runs inside your Kubernetes cluster and a client called helm that runs on your local machine. A package is called a chart to keep with the maritime theme.
With the Helm client, you can browse package repositories (containing published Charts) and deploy those Charts on your Kubernetes cluster. Helm will pull the Chart and talking to Tiller will create a release (an instance of a Chart).
We need to run following command to use helm.But before this we should have helm and tiller exe command installed.and put that into kubernetes folder.
Here helm init is used to initialise helm with repository.
helm repo add command is used to add stable repository to our helm that can used to install stable versions of softwares from helm hub public repository.
kubectl get pods -n kube-system command is used to see tiller-deploy is created or not.
kubectl -n kube-system create serviceaccount tiller command is used to create account on tiller or can say to configure tiller .
kubectl create clusterrolebinding command is used to link tiller to our cluster.
There is one more command not mentioned here
helm init --service-account tiller
This command is used to link helm with tiller.
9. Launch App on K8s
Now we can launch any application on k8s with the help of helm . I have installed jekins for demo.
Now our jenkins server (app) is launched successfully . To login to jenkins we need to run kubectl get secret command to get admin password .
Since this password is encoded with base-64 format so we need to decode it .
Finally we have successfully deployed our app and now can use it by creating different job in it.
I have explained all things from basic to advance.Hope after reading this article you have gained some knowledge.
Thanks
Hritick goyal