AMAZON EKS
Objectives-
- Create a kubernetes cluster using amazon eks and on that cluster launched a webserver using ELB,EBS.
- Deploy wordpress and mysql server on top of eks and integrated it with aws efs.
- Create a serverless compute using aws fargate.
What is EKS?
Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed kubernetes service. There is no need to manually configure or set up kubernetes cluster. EKS is deeply integrated with services such as Amazon CloudWatch, Auto Scaling Groups, AWS Identity and Access Management (IAM), and Amazon Virtual Private Cloud (VPC), providing you a seamless experience to monitor, scale, and load-balance your applications.
Also, EKS provides a scalable and highly-available control plane that runs across multiple availability zones to eliminate a single point of failure.
Created a kubernetes cluster using amazon eks and on that cluster launched a webserver using ELB,EBS.
Procedure-
- First we need to create a user with administrator access to create an eks cluster and integrate other services of amazon. Also we can access eks without any problem with this user.
- Configure aws cli for eksuser.
- Install eksctl in our pc so that we can manage eks using cmd line.
Do not forget to set the path of environmental variables.
- Time for creating our kubernetes cluster. We are going to do it by creating a yaml file(cluster.yml) in which the code for our infrastructure will be there.
Run the cmd "eksctl create cluster -f cluster.yml"
As the cluster is up we can acces it using kubectl cmd. In order to do so we need to configure our client so run cmd "aws eks update-kubeconfig --name lwcluster". Verify your cluster is successfully setup and connected by running "kubectl cluster-info".
To view the nodes running "kubectl get nodes". The nodes are running on ec2 instances which can be viewed in the aws console.
- Now we will create a namespace("myns") where we are going to launch our server.
This will create a namespace -"kubectl create ns myns"
The default namespace will be set to our myns - "kubectl config set-context --current --namespace=myns"
- We will create a deployment using docker image which is already configured for webserver and scale it out.
- Expose our deployment's port 80 and type is load balancer. Behind the scene EKS uses AWS ELB which is highly available and scalable.
Service is the program which exposed our deployment and the type of service we used is load balancer.
We can access the site using DNS name of load balancer. As it is a balancing the load between different pods the IP address is changing.
- Now we will make the storage persistent using pvc and behind the scene EKS takes storage from EBS.
There are no pvc or pv created.
We created the pvc using pvc.yml but it is pending state so we need to mount it.
Delete all and then again create the same deployment using deppvc.yml so that we can also mount the volume to our pods. We also created the load balancer again as we deleted the previous one.
Now you can see using aws webui that the volume is created.
Copy some file from pc to the container using kubectl cp
Finally our site is up, you can visit it using load balancer's DNS name
Deployed wordpress and mysql server on top of eks and integrated it with aws efs.
Procedure-
- We are going to create cluster using cluster.yml file but this time we are using spot instances and on-demand instances as spot instances are around 90% cheaper than on demand instances.
Run cmd "eksctl create cluster -f cluster.yml" and configure our client as shown above
Now the cluster is set up
- Time to deploy mysql and wordpress server integrated with efs.
Create a efs file system using aws webui in the same vpc where our kubernetes cluster is present . Also create a security group allowing all ingress and egress traffic in the eks cluster vpc.
Install amazon-efs-utils in all the slave nodes of our cluster manually.
To attach efs we need to create a deployment which act as a provisioner.
Mention the efs's domain name and id in the fields mentioned above.
I have created a folder for deploying the servers and other neccessary resources. I also created a kustomization file which contain all the resources files and our whole application can be deployed by running a single cmd .
Our whole cluster is deployed including the efs-provisoner
Finally you can use your wordpress site using the load balancer's dns name
Create a serverless compute using aws fargate.
What is AWS Fargate?
AWS Fargate is a serverless compute engine for containers that works with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). Fargate makes it easy for you to focus on building your applications. Fargate removes the need to provision and manage servers, lets you specify and pay for resources per application, and improves security through application isolation by design.
Fargate allocates the right amount of compute, eliminating the need to choose instances and scale cluster capacity. You only pay for the resources required to run your containers, so there is no over-provisioning and paying for additional servers. Fargate runs each task or pod in its own kernel providing the tasks and pods their own isolated compute environment. This enables your application to have workload isolation and improved security by design.
Procedure-
For launching Fargate we will create a file(fcluster.yml) in yaml format.
Now run the cmd "eksctl create cluster -f fcluster.yml"
This time the cluster is created but we can't see and access the instances(worker nodes) of our cluster as aws manages everything internally. So all you need to care about is your application.
Feel free to contribute !
Here is a link attached of my code
Thank You !