Deploying an Application on AWS EKS with Ingress: A Step-by-Step Guide

In this guide, we'll walk through the steps to set up an Amazon Elastic Kubernetes Service (EKS) cluster using Fargate (a serverless compute engine for containers). We'll also deploy a sample application and configure an Application Load Balancer (ALB) to make the app accessible. Let’s get started!

Step 1: Install Required Tools

Before we begin, you’ll need to install three essential tools:

  1. kubectl: A command-line tool for managing Kubernetes clusters. It allows you to deploy applications, inspect resources, and manage cluster operations.

  2. eksctl: A tool specifically designed for Amazon EKS. It simplifies the process of creating, managing, and scaling EKS clusters.

  3. AWS CLI: A command-line interface for interacting with AWS services. It’s used to configure and manage AWS resources.

Run the following command to install these tools on an Arch Linux-based system (or use the appropriate package manager for your OS):

sudo pacman -Sy kubectl aws-cli eksctl

Step 2: Configure AWS CLI

Once the tools are installed, you need to configure the AWS CLI with your credentials. This allows you to interact with your AWS account.

Run the following command and provide your Access Key ID, Secret Access Key, AWS Region, and preferred output format when prompted:

aws configure

Step 3: Create an EKS Cluster

Now, let’s create an EKS cluster using eksctl. We’ll use Fargate to run our workloads, which means we don’t need to manage EC2 instances—AWS handles the underlying infrastructure for us.

Run the following command to create a cluster named alpha in the ap-south-1 region:

eksctl create cluster --name alpha --region ap-south-1 --fargate

This process may take 10–15 minutes. Once completed, your EKS cluster will be up and running.

Step 4: Update kubeconfig

To interact with your EKS cluster using kubectl, you need to update your kubeconfig file. This file contains the necessary information to connect to your cluster.

Run the following command:

aws eks update-kubeconfig --name alpha --region ap-south-1

Step 5: Deploy the Application

We’ll deploy a simple game called 2048 as our sample application. To do this, we’ll use a pre-configured YAML file that defines the deployment, service, and ingress resources.

Run the following command to deploy the application:

kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/examples/2048/2048_full.yaml

Step 6: Create a Fargate Profile

Fargate profiles determine which pods should run on Fargate. Let’s create a Fargate profile for our application.

Run the following command:

eksctl create fargateprofile --cluster alpha --region ap-south-1 --name alb-sample-app --namespace game-2048

Step 7: Set Up IAM OIDC Provider

To allow the AWS Load Balancer (ALB) Controller to communicate with AWS resources, we need to configure an IAM OIDC provider for the cluster.

Run the following command:

eksctl utils associate-iam-oidc-provider --cluster alpha --approve

Step 8: Install the ALB Controller

The ALB Controller is responsible for creating and managing Application Load Balancers for your Kubernetes applications. To install it, follow these steps:

  1. Download the IAM Policy:

     curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.11.0/docs/install/iam_policy.json
    
  2. Create the IAM Policy:

     aws iam create-policy \
         --policy-name AWSLoadBalancerControllerIAMPolicy \
         --policy-document file://iam_policy.json
    

  3. Create an IAM Role for the ALB Controller: Replace <your-cluster-name> and <your-aws-account-id> with your actual cluster name and AWS account ID.

     eksctl create iamserviceaccount \
       --cluster=alpha \
       --namespace=kube-system \
       --name=aws-load-balancer-controller \
       --role-name AmazonEKSLoadBalancerControllerRole \
       --attach-policy-arn=arn:aws:iam::<your-aws-account-id>:policy/AWSLoadBalancerControllerIAMPolicy \
       --approve
    
  4. Install the ALB Controller using Helm: Helm is a package manager for Kubernetes. Run the following commands to add the Helm repository and install the ALB Controller:

     helm repo add eks https://aws.github.io/eks-charts
     helm repo update eks
     helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
       -n kube-system \
       --set clusterName=alpha \
       --set serviceAccount.create=false \
       --set serviceAccount.name=aws-load-balancer-controller \
       --set region=ap-south-1 \
       --set vpcId=<your-vpc-id>
    

Step 9: Verify the Deployment

To ensure everything is working correctly, check the status of the ALB Controller deployment:

kubectl get deployment -n kube-system aws-load-balancer-controller

Step 10: Access the Application

Once everything is set up, the ALB Controller will create a load balancer for your application. You can access the game using the DNS name of the load balancer. For example:

http://k8s-game2048-ingress2-067ca5a9c2-1851598133.ap-south-1.elb.amazonaws.com


Conclusion

Congratulations! You’ve successfully set up an EKS cluster using Fargate, deployed a sample application, and configured an Application Load Balancer. This setup is ideal for running serverless Kubernetes workloads without worrying about managing the underlying infrastructure.