Deploying a two-tier application on AWS EKS (Elastic Kubernetes Service) brings the benefits of managed Kubernetes to your infrastructure. With AWS EKS, you can efficiently handle the complexities of application scaling, load balancing, and secure access across cloud-native applications. In this guide, we’ll walk through setting up AWS EKS, configuring it for two-tier architecture, and deploying a sample application.

Introduction to Managed Kubernetes with AWS NGINX

Managed Kubernetes allows you to orchestrate and manage containerized applications, reducing the overhead of managing Kubernetes infrastructure. AWS EKS is Amazon’s managed Kubernetes service, enabling users to deploy, manage, and scale applications across highly available clusters. With AWS EKS, you benefit from the automation of provisioning, scaling, and maintenance of the control plane while still having complete control over application deployment.

Understanding Kubernetes Architecture: Control Plane vs. Data Plane

In Kubernetes, the architecture is split into two key components:

  1. Control Plane: Manages the cluster, handling tasks like scheduling, managing desired state, and monitoring. AWS EKS manages the control plane for you, ensuring high availability and security.
  2. Data Plane: Consists of worker nodes where containers run. With AWS EKS, you can choose the instance types and control the data plane according to your application’s requirements.

Overview of Managed Kubernetes Services: DOKS, GKE, AKS, EKS

While AWS EKS is Amazon’s managed Kubernetes offering, other cloud providers offer their solutions:

  • DigitalOcean Kubernetes Service (DOKS): A straightforward managed Kubernetes service ideal for smaller applications.
  • Google Kubernetes Engine (GKE): A robust option with Google’s advanced container management features.
  • Azure Kubernetes Service (AKS): A reliable choice for integrating with Microsoft services.

Each service has unique advantages, but AWS EKS stands out for applications requiring high scalability, integration with AWS services, and strong security controls.

Setting Up Kubernetes Cluster with AWS EKS

Creating an EKS cluster involves configuring the CLI, creating a Virtual Private Cloud (VPC), establishing IAM roles, and deploying the cluster.

Configuring AWS CLI and Kubectl for EKS Management

  1. Install AWS CLI: Download and install the AWS CLI.
  2. Configure AWS CLI: Run aws configure and provide your credentials, region, and output format.
  3. Install kubectl: Ensure you have kubectl, the Kubernetes command-line tool, installed. AWS offers kubectl installation instructions.

aws configure

kubectl version –client

Creating a New VPC for EKS: A Step-by-Step Guide

Creating a dedicated VPC for your EKS cluster improves network isolation and control.

  1. Navigate to the VPC console: In the AWS Management Console, go to VPC and create a new VPC.
  2. Subnet Configuration: Create public and private subnets across at least two availability zones.
  3. Internet Gateway: Attach an internet gateway to the VPC.
  4. Route Tables: Configure route tables for public subnets to connect to the internet gateway and for private subnets to connect internally within the VPC.

Establishing IAM Roles for EKS Cluster and Nodes

IAM roles control permissions for your EKS cluster and nodes.

  1. EKS Cluster Role: Create an IAM role with eks.amazonaws.com as the trusted entity. Attach the AmazonEKSClusterPolicy to this role.
  2. Node Role: Create another IAM role for the worker nodes with ec2.amazonaws.com as the trusted entity. Attach AmazonEKSWorkerNodePolicy, AmazonEC2ContainerRegistryReadOnly, and AmazonEKS_CNI_Policy.

aws iam create-role –role-name EKSClusterRole –assume-role-policy-document file://eks-trust-policy.json

aws iam attach-role-policy –role-name EKSClusterRole –policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy

Deploying a Two-Tier Application on AWS EKS

With AWS EKS set up, it’s time to deploy a two-tier application, typically consisting of a front end and back end. This separation improves scalability and manageability.

  1. Define Kubernetes Deployment YAML: Create two deployment YAML files, one for the frontend service and another for the backend. Each deployment will define replicas, container images, and ports.
  2. Create Kubernetes Services: Define services for each tier to manage internal and external access.

apiVersion: apps/v1

kind: Deployment

metadata:

  name: frontend

spec:

  replicas: 3

  selector:

    matchLabels:

      app: frontend

  template:

    metadata:

      labels:

        app: frontend

    spec:

      containers:

      – name: frontend

        image: nginx:latest

        ports:

        – containerPort: 80

Managing Services and Scaling in AWS EKS

Kubernetes simplifies application scaling with built-in support for horizontal scaling. For each tier, replicas can be easily scaled based on demand.

  1. Horizontal Pod Autoscaling: EKS supports Kubernetes’ native Horizontal Pod Autoscaler (HPA), which scales replicas based on CPU or custom metrics.
  2. Updating Deployment: Use kubectl scale to manually scale up or down as required.

kubectl scale deployment frontend –replicas=5

Accessing Applications via Load Balancers and Node Ports

To make your application accessible, use AWS’s integration with Elastic Load Balancers (ELBs) or define NodePorts for direct access.

  • Application Load Balancer (ALB): AWS EKS can automatically provision an ALB for your services. This is ideal for handling external traffic.
  • NodePort: You can configure services with NodePorts to expose a specific port on each node for internal access.

apiVersion: v1

kind: Service

metadata:

  name: frontend-service

spec:

  type: LoadBalancer

  selector:

    app: frontend

  ports:

  – protocol: TCP

    port: 80

    targetPort: 80

Conclusion

AWS EKS simplifies deploying two-tier applications, combining the power of Kubernetes with AWS’s scalability and management features. This guide has walked through setting up a cluster, creating VPCs, configuring IAM roles, and deploying a two-tier application. AWS EKS, with features like automatic scaling and load balancing, provides a strong foundation for managing applications that need high availability and resilience.

References

Tutorial: Deploy an application to Amazon EKS

How To Expose Multiple Applications on Amazon EKS Using a Single Application Load Balancer