AWS EKS Cluster: Setting up Your Cluster Like a Pro with eksctl

Sat Oct 28, 2023

Introduction

Kubernetes is the widely adopted solution for handling cloud-based containers, and Amazon EKS simplifies Kubernetes deployment on AWS

Amazon Elastic Kubernetes Service (EKS) is a fully managed Kubernetes service provided by AWS, making it easier to deploy, manage, and scale containerized applications using Kubernetes.

eksctl is a command-line tool for creating and managing EKS clusters.

In this guide, we'll walk you through the process of setting up a Kubernetes EKS cluster on AWS using the eksctl tool, empowering you to fully leverage containerized applications.

Prerequisites

Before we begin, ensure you have the following prerequisites in place:

  1. To get started, all you need is an active AWS account with permissions to create and manage EKS clusters. Everything else will be covered in the blog itself.

Step 1: Launch an EC2 Instance

First, we'll launch an Amazon Elastic Compute Cloud (EC2) instance type of t2.micro.

This instance will serve as the control center for creating and managing our EKS cluster. 

Step 2: Install and Configure AWS CLI

To install the AWS CLI, follow these commands:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Configure your AWS Access Key ID, AWS Secret Access Key, default region name, and default output format by using the "aws configure" command.

Note: 
  1.  You can find/ create your access keys in the IAM service under the user section. 
  2. Ensure that the user has administrative access/ Required access to setup EKS Cluster when configuring their Access keys.

Step 3: Installing kubectl

Kubectl is a command line tool that you use to communicate with the Kubernetes API server. 

Download the kubectl binary for your cluster's Kubernetes version-1.28 from Amazon S3

curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.28.2/2023-10-17/bin/linux/amd64/kubectl

(Optional) Verify the downloaded binary with the SHA-256 checksum for your binary.

curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.28.2/2023-10-17/bin/linux/amd64/kubectl.sha256
Check the SHA-256 checksum for your downloaded binary with one of the following commands.
sha256sum -c kubectl.sha256
openssl sha1 -sha256 kubectl
Apply execute permissions to the binary.

chmod +x ./kubectl
Copy the binary to a folder in your PATH. If you have already installed a version of kubectl, then we recommend creating a $HOME/bin/kubectl and ensuring that $HOME/bin comes first in your $PATH.

mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
After you install kubectl, you can verify its version.

kubectl version --client

Step 3: Installing eksctl

To download the latest release, run:

# for ARM systems, set ARCH to: `arm64`, `armv6` or `armv7`
ARCH=amd64
PLATFORM=$(uname -s)_$ARCH

curl -sLO "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"

# (Optional) Verify checksum
curl -sL "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_checksums.txt" | grep $PLATFORM | sha256sum --check

tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz

sudo mv /tmp/eksctl /usr/local/bin
Determine whether eksctl installed on your device or not

eksctl version

Step 4: Run the eksctl commands to create/delete/modify the EKS Cluster

Command to Create EKS Cluster using eksctl command

eksctl create cluster --name <name-of-cluster> --nodegroup-name <nodegrpname> --node-type <instance-type> --nodes <no-of-nodes>  

eksctl create cluster --name mycluster --nodegroup-name ng-test --node-type t2.medium --nodes 2

the above command will create an EKS cluster named "mycluster" with a node group named "ng-test." The node group will consist of two nodes, each using the "t2.medium" instance type.

it will take around 15-20 mins to setup the cluster. 

In background eksctl will trigger AWS Cloudformation to create the EKS Cluster. 

Test the EKS Cluster

Command to Delete EKS Cluster using eksctl command

eksctl delete cluster --name <name-of-cluster>  
eksctl delete cluster --name mycluster

Conclusion

I hope you enjoyed reading this blog and found it informative. If you have any questions or topics you'd like us to cover in future blogs, please don't hesitate to connect with me on LinkedIn. Thank you for joining us on this Kubernetes journey

Sampath Siva Kumar Boddeti
AWS & Terraform Certified