How to Create EKS Cluster Using AWS CLI

The AWS Command Line Interface (AWS CLI) may be used to create an Amazon Elastic Container Service for Kubernetes (EKS) cluster, providing a hands-on and customized approach to cluster management. This post will show you through the process of installing and configuring the AWS CLI, as well as how to construct an EKS cluster and set up the kubectl client tool.

Deploy an Amazon EKS Cluster using the AWS CLI, kubectl and eksctl

Overview

Step 1: Install AWS CLI and Configure

For this lab purpose , I have created workstation node on AWS platform by using Amazon Linux image which is pre-configured with AWS CLI. In order to configure AWS CLI please use below document as per operating system requirements.

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

To configure AWS CLI, Run below command.

[ec2-user@ip-172-31-24-209 ~]$ aws configure

This command will prompt you to enter your AWS access key ID, secret access key, default region name, and default output format. You can obtain your access key ID and secret access key from the AWS Management Console.

Step 2: Setup repository install and set up kubectl on Linux
https://v1-29.docs.kubernetes.io/docs/tasks/tools/install-kubectl-linux/

Add the Kubernetes yum repository. If you want to use Kubernetes version different than v1.30, replace v1.30 with the desired minor version in the command below.

[ec2-user@ip-172-31-24-209 ~]$ cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF

Install kubectl using yum:

[root@ip-172-31-24-209 ec2-user]# yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

Enable and start Kubelet service.

[root@ip-172-31-24-209 ec2-user]# systemctl enable --now kubelet
[root@ip-172-31-24-209 ec2-user]# systemctl start --now kubelet

Step 3: Install eksctl on Linux using curl command.
https://docs.aws.amazon.com/emr/latest/EMR-on-EKS-DevelopmentGuide/setting-up-eksctl.html

[root@ip-172-31-24-209 ec2-user]# curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
[root@ip-172-31-24-209 ec2-user]# sudo mv /tmp/eksctl /usr/local/bin
[root@ip-172-31-24-209 ec2-user]# eksctl version

Step 4: Create EKS Cluster
Now that you have the required network infrastructure in place, you can create the EKS cluster. You can create the cluster using the following command:
https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html

[root@ip-172-31-24-209 ec2-user]# eksctl create cluster --name=eksclicluster01 --region=eu-west-2 --zones=eu-west-2a,eu-west-2b,eu-west-2c --without-nodegroup

After you have run the create-cluster command, you need to wait for the cluster to be created. This can take several minutes. You can check the status of the cluster using the following command:

[root@ip-172-31-24-209 ec2-user]# aws eks describe-cluster --name eksclicluster

Step 5: Provide necessary IAM role and permissions for nodegroup creation.

[root@ip-172-31-24-209 ec2-user]# eksctl utils associate-iam-oidc-provider --region eu-west-2 --cluster eksclicluster01 --approve

Step 6: Create Node Group

EKS clusters consist of control plane nodes and worker nodes. You need to create a node group to run your workloads on the worker nodes. You can create a node group using the following command:

Please keep in mind that for this step, I have created the key pair “eksnodegroup”.


[root@ip-172-31-24-209 ec2-user]# eksctl create nodegroup --cluster=eksclicluster01 --region=eu-west-2 --name=production-project --node-type=t3.medium --nodes=2 --nodes-min=2 --nodes-max=4 --node-volume-size=20 --ssh-access --ssh-public-key=eksnodegroup --managed --asg-access --external-dns-access --full-ecr-access --appmesh-access --alb-ingress-access

After you have run the create-nodegroup command, you need to wait for the node group to be created. This can take several minutes. You can check the status of the node group using the following command:


[root@ip-172-31-24-209 ec2-user]# aws eks describe-nodegroup --cluster-name eksclicluster01 --nodegroup-name production-project

Once the node group has been created, you should now have a fully functional EKS cluster that you can use to run your containers.

Step 7: You can verify the cluster information using below commands.

[root@ip-172-31-24-209 ec2-user]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-192-168-1-180.eu-west-2.compute.internal Ready 4m9s v1.29.3-eks-ae9a62a
ip-192-168-80-227.eu-west-2.compute.internal Ready 4m3s v1.29.3-eks-ae9a62a
[root@ip-172-31-24-209 ec2-user]# eksctl get nodegroup --cluster=eksclicluster
CLUSTER NODEGROUP STATUS CREATED MIN SIZE MAX SIZE DESIRED CAPACITY INSTANCE TYPE IMAGE ID ASG NAME TYPE
eksclicluster usaproject ACTIVE 2024-05-28T20:04:08Z 2 4 2 t3.medium AL2_x86_64 eks-usaproject-9ac7e066-c40c-4d9b-a449-41b9726e10d7 managed

Let me know your thoughts in the comment section.