In my previous article , I have explained how to create Kubernetes EKS Cluster using AWS Console , Check the article here.

In this guide , I will show you how to create and manage EKS cluster using command line tool , eksctl.

What is eksctl?

eksctl is a command line utility to create and manage kubernetes cluster in EKS.

It is written in Go (programming language) , which uses cloudformation stack to launch EKS cluster in AWS.

Creating EKS Cluster using eksctl

First We need to install and Configure AWS CLI in our system.Refer this article to setup aws cli in your local system.

Then We have to install kubectl , a command line utility to deploy and manage applications in kubernetes cluster.

To install kubectl use the below commands.

curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.16.8/2020-04-16/bin/linux/amd64/kubectl
chmod +x ./kubectl

Then move it to the /usr/local/bin folder.By doing so , You dont need to type the full path to kubectl.

Now If you run the below command ,

kubectl version

You will get the following response,

Client Version: version.Info{Major:"1", Minor:"16+"

Now that we have configured kubectl to access the cluster.

Now we have to install eksctl in the local system.

Download and extract the latest version of eksctl using below command.

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

Then move the eksctl binary file to /usr/local/bin folder.

sudo mv /tmp/eksctl /usr/local/bin/

To verify the installation and the version of the eksctl , Run the below command.

sudo eksctl version
[ℹ]  version.Info{BuiltAt:"", GitCommit:"", GitTag:"0.13.0"}

We have instaled required packages in our system. lets go ahead and spin up the EKS cluster using eksctl.

We have to create a file eks-cluster.yml which will have all the required information for creating the cluster.

Add the below configurations into the file.

Here , We are going to launch an EKS cluster in the existing VPC and subnets.

Provide the required values.

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
   name: eks-testing
   region: ap-south-1

vpc:
   id: "vpc-XXXXXXXX"  # (must match VPC ID used for each subnet below)
   cidr: "172.31.0.0/16"       # (must match CIDR used by the given VPC)
   subnets:
     # must provide 'private' and/or 'public' subnets by availibility zone as shown
     public:
       ap-southeast-1a:
         id: "subnet-xxxxxxxx"
ap-southeast-1b:
id: "subnet-xxxxxxxx"

nodeGroups:
- name: eks-test-ng
instanceType: t2.medium
labels: { role: workers, env: test }
desiredCapacity: 2
ssh: allow: true # will use ~/.ssh/id_rsa.pub as the default ssh key

We are adding a node group to the EKS cluster with the desired instance count of 2 and the instance type : t2.medium.

You can make the necessary changes as per your requirement.

To create a cluster using eksctl , Use the below command.

Go to directory where you have created and configured eks-cluster.yml file.

and run this command,

sudo eksctl create cluster -f eks-cluster.yml

This will provide some information such as eksctl version , region where cluster will be created.

As we have added ssh parameter in the eks-cluster.yml file , It will add the SSH public key to the instances in the node group.

It will then create a clodformation stack for creating a cluster and the nodegroup.

once the cloudformation template is created , It will deploy the stack.

[ℹ]  building cluster stack "eksctl-eks-testing-cluster"
[ℹ] deploying stack "eksctl-eks-testing-cluster"

Once the Cluster is created , You will get the below message.

[✔]  EKS cluster "eks-testing" in "ap-south-1" region is ready

To check the installation , Type the below commands,

To list the nodes in the node group and the kubectl configuration is correct.

kubectl get nodes
kubectl get svc

NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.100.0.1           443/TCP   16m

Now that we have successfuly launched an EKS cluster in AWS using eksctl.

To delete the cluster, run the below command.

eksctl delete cluster -f eks-cluster.yml

Hope you find it helpful.Thanks for reading this article.

Check out my other articles.