Kubernetes Cluster with Amazon EKS

January 2, 2023

Amazon EKS (Elastic Container Service for Kubernetes) is a managed Kubernetes service that makes it easy for you 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.

      Creating an AWS EKS Role

        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.

        EKS cluster

        6. On the Add permissions tab, choose Next.

        EKSClusterRole

        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.

        https://s3.us-west-2.amazonaws.com/amazon-eks/cloudformation/2020-10-29/amazon-eks-vpc-private-subnets.yaml

        Creating Custom VPC for EKS Cluster

        Click Next.

        Specifying stack details

        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

        Setup AWS EKS Cluster from AWS Console

        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.

        Specify networking

        On Next Review and create the page, select Create.

        Review and create the page

        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

        Adding Node Groups

        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
         Node Group configuration

        Click next

        On Set compute and scaling configuration

        set compute & scaling configuration

        Set Node Group scaling configuration

        Setting 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.

        Node group network configuration

        On the Review and create the page, review your managed node group configuration and choose Create..

        Node group scaling configuration

        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

        1. Enter AWS Access Key ID.
        2. Enter AWS Secret Access Key.
        3. Enter Default region name (like eu-central, us-east etc.).
        4. 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

        Written by Manish Juneja

        Cloud Computing Insights and Resources

        Application Modernization: An Essential Step Towards Digital Transformation

        Application Modernization: An Essential Step Towards Digital Transformation

        What is Application Modernization and Why it is Important? The process of modernizing outdated software for newer computer paradigms, such …

        Application Modernization: An Essential Step Towards Digital Transformation Read More »

        Best Practices for Cost Optimization on AZURE Cloud 

        Best Practices for Cost Optimization on Azure Cloud Computing Services

        According to Microsoft, Azure has more than 68,000 partners and is a preferred choice for approximately 95% of Fortune 500 …

        Best Practices for Cost Optimization on Azure Cloud Computing Services Read More »

        AWS Security Group vs NACL

        AWS Security Group vs NACL AWS Cloud provides significant protection natively to build a networking stack. There are two main …

        AWS Security Group vs NACL Read More »