Amazon EKS (Elastic Container Service for Kubernetes) is a managed Kubernetes service that makes it easy to run Kubernetes on the AWS Cloud without managing the Kubernetes control plane.
In AWS Cloud, you can deploy worker nodes using defined AMIs, and with the help of CloudFormation, AWS EKS is responsible for provisioning, running, managing, and auto-scaling the Kubernetes control plane across multiple AWS Availability Zones for high availability, security, and scalability.
Step 1: Create an AWS EKS Role.
The First Step is to create an IAM role in AWS console for Kubernetes Cluster.
1. Open the IAM console at https://console.aws.amazon.com/iam/.
2. Choose Roles, then Create role.
3. Under Trusted entity type, select AWS service.
4. From the Use cases for other AWS services dropdown list, choose EKS.
5. Choose EKS – Cluster for your use case, and then choose Next.
6. On the Add permissions tab, choose Next.
7. For Role name, enter a unique name for your role, such as eksClusterRole
8. Choose Create role
Step 2: Create Custom VPC for EKS Cluster.
After completed the Role Creation, we will setup VPC for EKS Cluster. We will use CloudFormation Stack to setup Custom VPC.
Open up CloudFormation, and click the Create new stack button.
Click Next.
Provide Stack name and change VPC Block parameters for VPC Stack. Click Next. CloudFormation will setup New VPC in few Mins.
Step 3: Setup AWS EKS Cluster from AWS Console
Select Create cluster. If you don’t see this option, in the Create EKS cluster box, enter a name for your cluster, such as fantasyapp-cluster, and select Next step. You will most likely be able to see the Create cluster option as shown below
On the Specify networking page, select vpc-060b9ede2ad3dd102| fantasyapp-VPC from the VPC drop-down list. Leave the remaining settings at their default values and select Next.
On Next Review and create the page, select Create.
Adding Node Groups:-
Open the Amazon EKS console at https://console.aws.amazon.com/eks/home#/clusters.
Choose your cluster that you created, i.e fantasyapp-cluster.
select the Compute tab, and then choose Add Node Group
On the Configure node group page, fill out the parameters accordingly, accept the remaining default values, and then choose Next
- Name – Enter a unique name for your managed node group, such as fantasynode_apsouth1.
- Node IAM role name – Choose eksClusterRole
Click next
On Set compute and scaling configuration
Set Node Group scaling configuration
On the Specify networking page, select only the respective subnet which is created for the availability zone in which you want to create the node group.
On the Review and create the page, review your managed node group configuration and choose Create..
After created EKS-Cluster and node group Now Configure your system to communicate with Cluster. For that we require Kubelet and Kubectl. We can install from AWS-EKS-amended version of kubectl or directly from the Kubernetes websites.
Install AWS CLI on Linux:-
The latest AWS CLI version is 2. So download the AWS CLI.
curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”
Unzip the file using the following command.
unzip awscliv2.zip
Install the AWS CLI using the following command.
sudo ./aws/install
AWS CLI is installed successfully on Linux System.
aws –version
Configure IAM Credentials:
aws configure
- Enter AWS Access Key ID.
- Enter AWS Secret Access Key.
- Enter Default region name (like eu-central, us-east etc.).
- Enter Default output format. Allowed formats are json, yaml, text, and table.
Install eksctl :-
Download eksctl:
curl –silent –location “https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz” | tar xz -C /usr/bin/
Get the version of eksctl:
eksctl version
eksctl help
Install kubectl:-
Download kubectl:
curl -LO https://dl.k8s.io/release/v1.25.0/bin/linux/amd64/kubectl
mv kubectl /usr/bin/
chmod +x /usr/bin/kubectl
kubectl version –client –output=yaml
Creating a kubeconfig file for an AWS EKS cluster:-
aws sts get-caller-identity
Create or update a kubeconfig file for your cluster. Replace region-code with the AWS Region that your cluster is in and replace my-cluster with the name of your cluster.
aws eks update-kubeconfig –region ap-south-1 –name fantasyapp-cluster
By default, the resulting configuration file is created at the default kubeconfig path (.kube) in your home directory
Test your Configuration
kubectl get svc