Day 27- AWS Elastic Kubernetes Service(EKS)

Day 27- AWS Elastic Kubernetes Service(EKS)

Welcome to AWS EKS Exploration! 🌐

Today, let’s dive into the world of Elastic Kubernetes Service (EKS) by Amazon Web Services. 🚀

What is AWS EKS?

AWS EKS(Elastic Kubernetes Service) is a managed service that eliminates things like installation of the Kubernetes and maintaining the Kubernetes cluster.

Some basic benefits like you can focus on deployment for the applications. You don’t need to think about the availability of your cluster, AWS will take care of those things.

Key features of EKS:

  • Manage Control Plane: In EKS, the Control Plane will be managed by AWS itself.
  • Configure Node Groups: In EKS, You can add multiple Worker Nodes according to the requirements in no time.
  • Cluster Scaling: AWS will take care of the Cluster scaling according to your requirements whether it’s upscaling or downscaling.
  • High Availability: AWS provides high availability of your Kubernetes cluster.
  • Security: AWS enhances the security by integrating IAM service with EKS.
  • Networking: AWS provides better control to manage the networking stuff for your Kubernetes cluster.

If you want to read more features in a detailed way refer to the following link:

https://aws.amazon.com/eks/features/

AWS EKS Costing

AWS will cost you 0.10$ per hour for each cluster. If you create EC2 for Node Groups then it will cost you separately according to the instance type and the same with ECS Fargate(depends on vCPU and memory resources).

Let’s Dive into the Demo! 🛠️

To create EKS, we need to configure VPC and other networking things. If you are not a beginner in the cloud feel free to skip the network configuration part. But if you are new to EKS or the AWS Cloud, I would say to follow each step. So, it will help you to get a better understanding of each service that is related to AWS EKS.

Create VPC and select the desired IPv4 CIDR.

We need to create at least two Public Subnets to ensure high availability.

Public-Subnet1

Public Subnet2

We need an internet connection for our clusters and worker nodes. To do that, create an Internet Gateway.

Now, attach the above Internet Gateway to the VPC that we created in the earlier step.

We need to create a route table as well for the internet access for each subnet.

Public Route table

Select the Internet Gateway in the Target.

Once you add routes, then you have to add subnets for which purpose we are creating a Public Route table.

Click on Edit subnet associations.

Select both subnets and click on Save associations.

Once you associate the subnets. You will see your subnets look like the below snippets.

Now, the EKS Cluster needs some access to the AWS Services like ec2, kms, and load balancer.

To do that, we will create an IAM Role and Policy for the EKS Cluster

Click on AWS service as a Trusted entity type and select the EKS as Usecase and in the below options, choose EKS-Cluster.

Click on Next.

Provide the Role name

Once we created the roles for the EKS Cluster. Now, we have to create a role for the Worker Nodes which is also a necessary part.

Click on AWS service as a Trusted entity type and select the EC2 as Usecase and in the below options, choose EC2.

When you will get a popup to add the Policy for the Worker Nodes.

Select the below three policies for our Worker Nodes.

AmazonEC2ContainerRegistryReadOnly, AmazonEKS_CNI_Policy, and AmazonEKSWorkerNodePolicy

Provide the name of the Role and click on next.

Now, Prerequisites are completed. Let’s create the EKS

Navigate to the AWS EKS and click on Add cluster.

Select Create.

Provide the name of your EKS Cluster then select the Cluster role that we have created for EKS Cluster and rest of the things will be as they as and click on Next.

In the network configuration,

Select the vpc that we created earlier with both subnets. Apart from that, others will be as it is, and click on Next.

Keep the default things as it is and click on Next.

Keep the default things as it is and click on Next.

Keep the default things as it is and click on Next.

Keep the default things as it is and click on Create.

After clicking on Create, AWS will take around 4 to 5 minutes to create the EKS. Meanwhile, let’s install Kubectl to work on AWS EKS.

curl -O s3.us-west-2.amazonaws.com/amazon-eks/1.28...

curl -O s3.us-west-2.amazonaws.com/amazon-eks/1.28...

sha256sum -c kubectl.sha256

openssl sha1 -sha256 kubectl

chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc

kubectl version — client

Install eksctl on the local machine (Optional)

ARCH=amd64
PLATFORM=$(uname -s)_$ARCH
curl -sLO "github.com/eksctl-io/eksctl/releases/latest.."
curl -sL "github.com/eksctl-io/eksctl/releases/latest.." | grep $PLATFORM | sha256sum - check
tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz
sudo mv /tmp/eksctl /usr/local/bin

Now, check the status of EKS whether it is Active or Not.

Once the status of EKS is Active, run the below command.

aws eks update-kubeconfig — region us-east-1 — name EKS-Cluster-Demo

If you are getting the error which is showing below in the snippet. Then, don’t worry. Let’s solve it in the next step.

Replace the ‘alpha’ with ‘beta’ like below snippet

Now, run the command again to update the config

aws eks update-kubeconfig — region us-east-1 — name EKS-Cluster-Demo

It’s working

Trying to deploy the pod but it is in pending status because there is no worker node present where the pod can be created.

To create a worker node, Select the EKS Cluster and navigate to the Compute section.

Click on Add node group.

Provide the name of your worker node and select the Worker Node role that we created earlier.

You can modify things according to your requirements. But the instance type t3.medium will be good because Kubernetes needs at least 2CPU.

Select the Subnets of the VPC that we have created above and click on Next.

Once the node is in Active status. Then, you can follow the next step.

Run the below command and you will see that our pending pod is now in running state.

kubectl get pods

Now, delete the previous, and let’s try to run the static application on the nginx server with the AWS load balancer

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-app-deployment
labels:
app: nginx-app
spec:
replicas: 2
selector:
matchLabels:
app: nginx-app
template:
metadata:
labels:
app: nginx-app
spec:
containers:
- name: nginx-container
image: avian19/nginx-ne:latest-1.0
ports:
- containerPort: 80

kubectl apply -f deployment.yml

Now, host the application outside of the Kubernetes Cluster by creating a service for the nginx application and observing the load balancer dns in the EXTERNAL-IP Column.

apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx-app
type: LoadBalancer
ports:
- protocol: TCP
port: 80

kubectl apply -f svc.yaml

Now, navigate to AWS Console and go to the Load Balancer section.

Copy the Load balancer DNS then, hit on the browser and see the magic.

Conclusion

AWS EKS simplifies Kubernetes management, allowing you to focus on application deployment. Today’s journey introduced the basics, key features, costing, and a hands-on demo. Explore the power of EKS and stay tuned for more Kubernetes adventures! 🚀💡

Want to Know About Challenge?

If you’re eager to learn more and join our challenge through the GitHub Repository, stay tuned for the upcoming posts. Follow for more exciting insights into the world of Kubernetes!

GitHub Repository: https://github.com/AmanPathak-DevOps/30DaysOfKubernetes

#Kubernetes #DaemonSet #StatefulSets #NetworkPolicy #Operators #ContainerOrchestration #DevOps #EKS #AWS #K8sLearning

See you on Day 28 as we unravel more Kubernetes mysteries!

Stay connected on LinkedIn: LinkedIn Profile

Stay up-to-date with GitHub: GitHub Profile

Feel free to reach out to me, if you have any other queries.

Happy Learning