Introduction
EKS is a managed kubernetes service and it helps us greatly by abstracting most of the infrastructural concerns regarding control plane, softwares etc. which make it easy for us to focus more on application deployment side.
Earlier I have written a post which shows a simple way to deploy an application to local kubernetes cluster. We also covered how to create an EKS kubernetes cluster in one of the earlier post. Today, I would like to take that very sample web application which we deployed to local kubernetes cluster and deploy it to EKS.
So, this post will be continuation of what we have already covered. If you are new to these topics, please check the above mentioned posts and then it will be easy to follow along.
Setting the Scene
We have a typical web application with following kubernetes resource structure from earlier posts:
Web part is build using Angular and .NET Core Web API and database part is using PostgresSQL. Then we have kubernetes services and deployment for each part.
Next, I have created an EKS cluster for the application with following command:
eksctl create cluster `
--name ab-cluster `
--nodegroup-name standard-workers `
--node-type t3.micro
--nodes 3 `
--nodes-min 1 `
--nodes-max 4 `
--node-ami auto
The application source-code, docker files and K8 yaml files can be downloaded from this git repository. This is the same codebase used in previous posts.
Deploying Web Application to Kubernetes
To start with deploying to EKS, I created a new folder (eks) under application code folder and copied previously created local kubernetes deployment files (k8s folder) to this folder (so what new changes I make, can be made to this copy). I then updated accounting-web.yml file with replicas information as shown below. I did not make changes to any other files.
Next, open up a PowerShell window inside eks folder and apply the yml files as shown below:
kubectl apply -f .\accounting-db.service.yml
kubectl apply -f .\accounting-db.deploymet.yml
kubectl apply -f .\accounting-web.yml
here is the output:
Now, if we execute kubectl get all command, we will see that kubernetes resources are created and we can also see the LoadBalancer address which we can open in a browser (notice port 8080 in the URL)
Here is the AWS Created loadbalancer in the web console:
AWS also created EC2 instances which are running our workload:
There are other AWS resources created such as VPC, Internet Gateway, Security Groups to make all this happen.
Lets visit the public address of load balancer and our web application dashboard will show-up. We can add some data and navigate around:
However, I do not like that we need to add port 8080 in the address. Lets change this to default port 80:
we can save the file and apply this change via kubectl as shown below:
and as you can see that only the service is configured and the deployment/pod is unchanged.
and if we execute kubectl get all command again:
our application shows up again and with existing data:
Note: I will delete this EKS and you might not be able to visit it online, but all the source code is available to you, give it a try and deploy it yourself as exercise.
Deleting Kubernetes Resources
Once you are done with your testing, you can delete the kubernetes resources and cluster as shown below:
We can delete the resources using following commands:
kubectl delete -f .\accounting-db.deploymet.yml
kubectl delete -f .\accounting-db.service.yml
kubectl delete -f .\accounting-web.yml
Next, we can delete the cluster using following command:
eksctl delete cluster --name ab-cluster
and you can also confirm via AWS web console that all of our cluster resources are deleted.
Summary
In this post, we saw a very basic example to deploy an application to EKS. We used the same kubernetes yaml files which we previously used to deploy to local kubernetes cluster and we saw that it worked as expected. This shall give us a good starting point to cover more advanced scenarios in future.
As we know that pods are ephemeral and currently our data will be lost if pod dies. We did not cover storage in kubernetes and how to use AWS storage options. We will cover those in next posts.
You can download the source code from this git repository.
Let me know if you have some comments or questions. Till next time, happy coding.
Summary
Discover more from Hex Quote
Subscribe to get the latest posts sent to your email.
1 thought on “Deploy a Web Application using AWS Elastic Kubernetes Service (EKS)”
Comments are closed.