AWS in Plain English

New AWS, Cloud, and DevOps content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Setting up Amazon EKS Cluster in the fastest and easiest way

--

Amazon Elastic Kubernetes Service (EKS) is a managed Kubernetes (k8s) offering from AWS. There are many ways in which EKS can be setup but in this post we will look at how to setup EKS in the fastest and easiest way possible.

We are going to use AWS CloudShell, eksctl and kubectl to create our EKS cluster.

AWS CloudShell is a browser-based shell available from the AWS Management Console.

eksctl is a command line tool for working with EKS clusters that automates many individual tasks.

kubectl is a command line tool to work with k8s.

Note : You will incur charges for resources created. However if you delete the cluster at the end of it, charges will be minimal.

Steps

Step 1 : Launch AWS CloudShell (Supported only in few regions)

I am using Mumbai (ap-south-1) region for this post. All the commands are executed from AWS CloudShell.

Step 2 : Install eksctl

2.1 Download eksctl

curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp

2.2 Move eksctl to /usr/local/bin or /home/cloudshell-user/bin folder

sudo mv /tmp/eksctl /usr/local/bin#or (persits in cloudshell)
sudo mv /tmp/eksctl /home/cloudshell-user/bin

2.3 Test the installation by checking the version

eksctl version

In my case it is (0.67.0)

Step 3 : Create Key Pair

Note : You can use existing key pairs as well so replace the key apprpriately.

This key is used to connect to EC2 nodes created by EKS cluster.

aws ec2 create-key-pair --key-name eksKeyPair --query 'KeyMaterial' --output text > eksKeyPair.pem

Step 4 : Create EKS Cluster

Create cluster with the default settings. This may take around 15–20 minutes so take a cup of coffee !

eksctl create cluster \
--name test-cluster \
--region ap-south-1 \
--with-oidc \
--ssh-access \
--ssh-public-key eksKeyPair

This should show the output on similar lines.

Some of the key resources created by eks are

  • VPC with total six subnets — 3 public and 3 private subnets and spans them across different AZs
  • One nodegroup with two nodes
  • Saves kubeconfig as “/home/cloudshell-user/.kube/config” so that we can connect to EKS cluster subsequently

Step 5 : Install kubectl

5.1 Download kubectl

curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl

5.2 Apply execute permission

chmod +x ./kubectl

5.3 Move the kubectl to different folder and add it to the path

mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin

5.4 (Optional) Add the $HOME/bin path to your shell initialization file so that it is configured when you open a shell.

echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc

5.5 Verify kubectl

kubectl version --short --client

Step 6 : View Resources using kubectl

kubectl get nodes -o wide

This shows two nodes are created using Amazon Linux2 AMI and runs Docker Container Runtime on the nodes. The nodes are having Internal IP (Private IP) and External-IP (Public IP).

To get the pods running in the cluster

kubectl get pods --all-namespaces -o wide
System Pods running on EKS cluster with no workload

kube-proxy is a network proxy that runs on each node of the cluster, implementing part of the Kubernetes Service concept. It maintains network rules on nodes. These network rules allow network communication to the Pods from network sessions inside or outside of the cluster.

core-dns is a flexible, extensible DNS server that can serve as the Kubernetes cluster DNS.

aws-node- pod is the Amazon VPC Container Network Interface (CNI) plugin for Kubernetes. These are deployed with each of the Amazon EC2 nodes as a Daemonset with the name aws-node. This handles the allocation of network interfaces , associated private IP addresses and wiring the host network.

Step 7 : View Cluster and Pods via AWS Console (Optional).

Following screeenshot shows that test-cluster is in Active state.

Cluster View

This cluster contains two nodes of m5.large type as shown below.

Workloads tab shows the Pods running inside the cluster.

Step 8 : (Optional) Run three nginx pods

The deployment manifest looks like below.

Sample nginx-deployment

As this is readily available you can execute the following command from CloudShell which should run three nginx pods on the EKS cluster

kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml

Verify if the pods are running in EKS by executing following command.

kubectl get pods

The same can be verified from EKS console as well. !

Step 9 : Delete EKS Cluster

If you do not want to use the EKS cluster then it is recommended to delete the cluster to avoid any charges.

eksctl delete cluster --name test-cluster

You should see output similar to the one below after it is deleted.

Delete EKS Cluster

Summary

Using eksctl is the easiest and fastest way to setup EKS cluster. The default options of eksctl creates VPC with total 6 subnets ,3 Public and 3 Private Subnets and spans across AZz. It also creates single nodegroup with two nodes with m5.large instance type.

Once the cluster is setup you can use kubectl to connect to the EKS cluster and deploy the applications !

This is good start for many of us. However this is just the begining and in subsequent posts we will look at how the EKS sets-up its networking and its implications.

Stay tuned !

https://www.buymeacoffee.com/amodkadam

References

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

eksctl : https://eksctl.io

kubectl : https://kubernetes.io/docs/reference/kubectl/overview/

In Plain English 🚀

Thank you for being a part of the In Plain English community! Before you go:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in AWS in Plain English

New AWS, Cloud, and DevOps content every day. Follow to join our 3.5M+ monthly readers.

Written by Aamod Kadam

AWS Community Builder | upGrad Course Author | 7 x AWS | Terraform Associate | Cloud Consulting | AWS | Azure | Docker | Kubernetes | Software Architecture

Responses (2)

Write a response