DEV Community

Cover image for Simple steps to create AWS EKS Cluster and Nodes
Shubham Srivastava
Shubham Srivastava

Posted on

Simple steps to create AWS EKS Cluster and Nodes

Amazon Elastic Kubernetes Service (EKS):

Kubernetes is a set of open source tools that automates deployment , management and scaling of containerized applications. AWS EKS is a wrapper around Kubernetes that provides managed service to maintain Kubernetes control plane. As it is managed by AWS you do not need to install , scale , maintain and operate control plane.

Since cloudformation templates are the simplest approach to describe and deliver infrastructure declaratively while utilising maintainability and reusability, I have used them to create Clusters and Nodes.

Prerequisites:

  • An active AWS account.
  • Basic knowledge of AWS services specifically IAM,EKS and CloudFormation.
  • AWS CLI and Kubectl installed and configured on local machine.

1. Create EKS Cluster

Here is the CloudFormation template for EKS cluster creation. This comprises 3 sections Template Version, Parameters and Resources.

AWSTemplateFormatVersion:

Version of the CloudFormation template.

Parameters:

Required values that we will pass dynamically while creating stack using AWS CLI

Resources:

AWS resources required for the EKS cluster.

Image description

Save this file as AWS-EKSClusterTemplate.yml in your local machine and replace default values in Parameters sections and run below command that will create CloudFormation Stack and EKS Cluster.

Please do not forget to replace default values with your AWS services as these values are specific to my AWS account and will give error. You can use default VPC, Subnet and EC2 key pair from your AWS account.

aws cloudformation create-stack --stack-name myClusterStack --template-body file://AWS-EKSClusterTemplate.yml --capabilities CAPABILITY_NAMED_IAM
Enter fullscreen mode Exit fullscreen mode

2. Create EKS Nodes:

Here is the cf template for EKC Nodes creation.

Image description
Image description

Save this file as AWS-EKSNodesTemplate.yml in your local machine and replace default values in Parameters section and run below command to create CloudFormation Stack and EKS Nodes.

aws cloudformation create-stack --stack-name myNodeStack --template-body file://AWS-EKSNodesTemplate.yml --capabilities CAPABILITY_NAMED_IAM
Enter fullscreen mode Exit fullscreen mode

Login to AWS account and check stack status. This process might take sever minutes. Once its complete stack status must show completed as below.

Image description

3. Use kubectl to check nodes in cluster and deploy first docker image.

Run kubectl get nodes command in your terminal, it will show 1 node in ready state.

Image description

If you have not configured kubectl to connect to newly created EKS cluster then run below command.

aws eks update-kubeconfig --name MyWebCluster

Now our environment is ready for deployment. Let's deploy and test nginx webserver using below command.

kubectl run nginx --image=nginx

Image description

Now, the port-forward feature of kubectl simply tunnels the traffic from a specified port at your localhost machine to the specified port on the pod.

Image description

Finally, pod is running and serving at port 8080. You can test application by visiting (http://localhost:8080) in web browser.

Image description

4. Clean Up

Cleaning up all the resources that were created above is crucial; failing to do so will result in significant expenses.

aws cloudformation delete-stack --stack-name myNodeStack
aws cloudformation delete-stack --stack-name myClusterStack

Conclusion:

AWS EKS simplifies managing containerized applications by offering a scalable, secure, and Kubernetes-based platform. If you're looking for agility and a focus on development, EKS lets you offload cluster management to AWS. Consider EKS for your next containerized project!

Top comments (0)