A Step-by-Step Guide to Creating and Managing an Amazon EKS Cluster on AWS

Amazon Elastic Kubernetes Service (EKS) offers a robust platform for deploying, managing, and scaling containerized applications using Kubernetes. In this hands-on tutorial, we will walk you through the process of creating an Amazon EKS cluster and managing it effectively. By the end of this tutorial, you will have a fully functional EKS cluster ready for deploying your applications.

Prerequisites:

  1. An AWS account.
  2. Basic familiarity with AWS services.

Step 1: Sign in to AWS Management Console

  1. Click on the “Open Console” button, which will redirect you to the AWS Management Console in a new browser tab.
  2. On the AWS sign-in page, leave the Account ID as the default value. Do not edit or remove the 12-digit Account ID.
  3. Copy your User Name and Password from the Lab Console to the IAM Username and Password fields in the AWS Console. Then, click on the “Sign-in” button.
  4. Once signed in, set the default AWS Region to “US East (N. Virginia)” (us-east-1).

Step 2: Create an Environment in CloudShell

  1. Ensure that you are in the “N.Virginia” Region.
  2. Click on the “CloudShell” icon located on the top right of the AWS menu bar.
  3. A new browser tab will open. If you see a welcome message for CloudShell, click on the “Close” button in that message.
  4. Wait for a few minutes while the environment is being created. Once ready, you will have access to the terminal.

Step 3: Install AWS CLI, eksctl, and kubectl

Before proceeding with the cluster setup, we need to install essential tools. Follow these steps:

  1. Wait for the CloudShell Environment: First, ensure that the CloudShell environment is fully initialized. You’ll need it for the following installations.
  2. Install AWS CLI: To install the AWS Command Line Interface (CLI) using the package manager yum, execute the following command in the terminal:sudo yum install awscli -y After installation, verify the AWS CLI version to ensure it was installed correctly: aws --version
  3. Install eksctl: We’ll also need eksctl, a tool for managing Amazon EKS clusters. To install it, copy and paste these two commands one after the other: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 Confirm that eksctl was installed successfully by checking its version:
    • eksctl version
  4. Download and Set Up kubectl: kubectl is the command-line tool for interacting with Kubernetes clusters. Follow these steps to install it:
    • Download the Amazon EKS vendored kubectl binary for your cluster’s Kubernetes version:curl -o kubectl https://amazon-eks.s3.us-east-1.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl
    • Make the downloaded binary executable:chmod +x ./kubectl
    • Copy the binary to a folder in your PATH and update your PATH environment variable to include the new directory:mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
    To verify the kubectl installation, run the following command:kubectl version --short --client

By completing these steps, you’ll have the necessary tools installed and configured to manage your Amazon EKS cluster effectively.

Step 4: Create an EKS Cluster

To create an EKS Cluster, use eksctl with the following command:

eksctl create cluster --version=1.27 --name=eksspottutorial --nodes=2 --managed --region=us-east-1 --zones us-east-1a,us-east-1b,us-east-1c --node-type t2.medium --asg-access

Note: Do not close the CloudShell tab. This process may take 20–25 minutes.

During this time, you can monitor the EKS Cluster creation status and other events in the CloudFormation console.

  1. Navigate to CloudFormation by clicking on “Services” and selecting “CloudFormation” in the “Management & Governance” section.
  2. On the left sidebar, click on “Stacks.” You will see a new CloudFormation stack with the status “CREATE_IN_PROGRESS.”
  3. Click on the stack names “eksctl-eksspottutorial-cluster” and “eksctl-eksspottutoriall-nodegroup-ng” to explore events and resources.
  4. Once the VPC resources are created, you will be able to see EKS Cluster creation.
  5. Check the current status of the EKS Cluster in CloudShell:arduinoCopy codekubectl get nodes

Step 5: Create Spot Managed Node Groups

To create node groups, run the following command:

eksctl create nodegroup --cluster=eksspottutorial --managed --region=us-east-1 --spot --name=spot-node-group-2vcpu-8gb --instance-types=t2.small,t2.micro,t2.medium --nodes-min=2 --nodes-max=5 --asg-access

This command will add spot-managed node groups to your EKS Cluster, which may take around 10 minutes. Monitor the Node groups creation status in the CloudFormation console.

To view the nodes, run the following command:

kubectl get nodes --show-labels --selector=eks.amazonaws.com/capacityType=SPOT | grep SPOT

Step 6: Deploy the Kubernetes Cluster Autoscaler

  1. Download the YAML file required for deploying the latest version of Kubernetes cluster autoscaler:curl -LO https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
  2. Update the tags for Cluster autoscaler and its version:sed -i 's/eksspottutorial/eksspottutorial/g' cluster-autoscaler-autodiscover.yaml sed -i 's/v1.17.3/v1.20.0/g' cluster-autoscaler-autodiscover.yaml
  3. Deploy the Cluster Autoscaler:Copy codekubectl apply -f cluster-autoscaler-autodiscover.yaml

Step 7: Deploy the Sample App

  1. Create a file named nginx-to-scaleout.yaml:bashCopy codetouch nginx-to-scaleout.yaml
  2. List all S3 Buckets and copy the one starting with the name “xlabession”:aws s3 ls
  3. Paste the contents into nginx-to-scaleout.yaml using the S3 Bucket and replace the copied bucket name with the one you found.
  4. Deploy the deployment file and confirm the deployment:kubectl apply -f nginx-to-scaleout.yaml kubectl get deployment/nginx-to-scaleout
  5. Scale the deployment to run 5 replicas:kubectl scale --replicas=5 deployment/nginx-to-scaleout
  6. Check the deployed pods:kubectl get pods

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top