Creating an Amazon EKS Cluster from scratch using eksctl
Tags: aws, kubernetes, cloud, devops
Published: 2022-03-30 14:47:45

Hi folks, to create an EKS cluster, you require a launch pad, for today we shall be using an Amazon Linux 2 EC2 server as our eks launchpad. There are few pre-requisites we require to take care of -
- kubectl: Kubernetes Client to communicate with the Kubernetes API Server. <br> 

Installing kubectl: [Source: [Installing kubectl - AWS Docs](https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html)]

```
curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
kubectl version --client
```

- eksctl: The official Amazon EKS CLI, used to create and manage multiple EKS Clusters.

Installing eksctl: [Source: [Installing eksctl - eksctl docs](https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html)]

```
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
export PATH=$PATH:/usr/local/bin
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc
eksctl version
```

Create an IAM Role for EC2 with following IAM policies: 
[Source : eksctl doc](https://eksctl.io/usage/minimum-iam-policies/)

Once the Role is created you can attach the role onto your EKS Launch Pad Server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/de62mqi1wsldrrodxauw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgke2pojrrnrr7xvuw8t.png)
   

## Once the pre-requisites has been taken care of we can go ahead with cluster creation.

- Create a file named cluster.yaml with the following configuration: [Source: My GitHub - cluster.yaml](https://github.com/RajitPaul11/AmazonEKS/blob/master/EKS-Managed-NodeGroups-Cluster/cluster.yaml)

- Run eks create cluster with dry run
`eksctl create cluster -f cluster.yaml --dry-run`

> [ This shall help you identify any errors on the config files or related to your permission, make sure you don't have additional aws user configured with less privileges than the privileges allowed in the EC2 attached role. ]

- Launch your cluster with
`eksctl create cluster -f cluster.yaml`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9dff8alr69hvr7bq2q68.png)
 
- You need to wait for a few minutes and you shall see on the screen the CFN Stack is being deployed
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpognx4qdzdzpng3rrpn.png)

> The CFN stack creates the  EKS Control Plane, SG's, Policies and Service Roles. It also creates a single nodegroup or more as mentioned in the cluster config.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/647yycyxzytq7ao23ulv.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f9vy6ssfb5zm09q11ii1.png) 

If you encounter any issues check the Cloudformation Console or try:
`eksctl utils describe-stacks --region=Your-Region --cluster=Your-Cluster-Name`
 
The EKS cluster has been successfully created 🎉
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06ekxjqk0dh25mjg8808.png)
 
You can access the EKS cluster from your launch pad using kubectl!
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sdfy339tx52m1op5rehj.png)

### Clean UP
To delete the EKS Cluster run:
`eksctl delete cluster your-cluster-name`
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fso3t2rp8hwb63hrhb88.png)

I hope you enjoyed the blog, if you face any issues please reach out to me on [LinkedIn](https://www.linkedin.com/in/rajitpaul/) and we can discuss the same, thanks! 

### Wrap Up
You can follow me to get updated on new AWS related blogs in the coming weeks, also I am an earth buddy, don't know what that is, check this out: [Save our Soil](https://consciousplanet.org/action-now)
###Adios!