DEV Community

Rajit Paul for AWS Community Builders

Posted on

Creating an Amazon EKS Cluster from scratch using eksctl

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.

Installing kubectl: [Source: Installing kubectl - AWS Docs]



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


Enter fullscreen mode Exit fullscreen mode
  • eksctl: The official Amazon EKS CLI, used to create and manage multiple EKS Clusters.

Installing eksctl: [Source: Installing eksctl - eksctl docs]



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


Enter fullscreen mode Exit fullscreen mode

Create an IAM Role for EC2 with following IAM policies:
Source : eksctl doc

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

Image description

Image description

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

  • 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

  • You need to wait for a few minutes and you shall see on the screen the CFN Stack is being deployed Image description

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

Image description

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

You can access the EKS cluster from your launch pad using kubectl!
Image description

Clean UP

To delete the EKS Cluster run:
eksctl delete cluster your-cluster-name
Image description

I hope you enjoyed the blog, if you face any issues please reach out to me on LinkedIn 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

Adios!

Top comments (0)