How do you deploy a web application on AWS using Amazon EKS and expose it to the internet?

How do you deploy a web application on AWS using Amazon EKS and expose it to the internet?

Scenario:

You’ve developed a simple web application consisting of a React frontend and a Node.js backend. You want to deploy this application using Kubernetes on AWS, and ensure it is accessible over the internet.

Solution Breakdown:

  1. Choosing the AWS Service:

    Amazon EKS (Elastic Kubernetes Service)

    • Why EKS?: Amazon EKS is a managed Kubernetes service that simplifies the deployment and management of Kubernetes clusters on AWS. With EKS, AWS handles the management of the Kubernetes control plane, providing high availability, scalability, and integrated security features.
  2. Deploying Your Application:

    • Create an EKS Cluster:

      • Go to the AWS Management Console and navigate to Amazon EKS.

      • Create a new EKS cluster by specifying the cluster name, Kubernetes version, and networking settings (VPC, subnets, etc.).

      • Create or select a managed node group which consists of EC2 instances to run your application pods.

    • Configure kubectl:

      • After creating the cluster, configure kubectl (the Kubernetes CLI) to interact with your EKS cluster using AWS CLI or aws-iam-authenticator.
    • Prepare and Apply Kubernetes Manifests:

      Example Kubernetes Manifests:

      • Backend API Deployment (backend-deployment.yaml):

          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: backend-api
          spec:
            replicas: 3
            selector:
              matchLabels:
                app: backend-api
            template:
              metadata:
                labels:
                  app: backend-api
              spec:
                containers:
                - name: backend-api
                  image: your-docker-repo/backend-api:latest
                  ports:
                  - containerPort: 8080
        
      • Backend API Service (backend-service.yaml):

          apiVersion: v1
          kind: Service
          metadata:
            name: backend-api-service
          spec:
            selector:
              app: backend-api
            ports:
              - protocol: TCP
                port: 80
                targetPort: 8080
            type: LoadBalancer
        
      • Frontend Deployment (frontend-deployment.yaml):

          apiVersion: apps/v1
          kind: Deployment
          metadata:
            name: frontend
          spec:
            replicas: 2
            selector:
              matchLabels:
                app: frontend
            template:
              metadata:
                labels:
                  app: frontend
              spec:
                containers:
                - name: frontend
                  image: your-docker-repo/frontend:latest
                  ports:
                  - containerPort: 3000
        
      • Frontend Service (frontend-service.yaml):

          apiVersion: v1
          kind: Service
          metadata:
            name: frontend-service
          spec:
            selector:
              app: frontend
            ports:
              - protocol: TCP
                port: 80
                targetPort: 3000
            type: LoadBalancer
        
      • Deploy to EKS:

        • Use kubectl to apply the manifests:

            kubectl apply -f backend-deployment.yaml
            kubectl apply -f backend-service.yaml
            kubectl apply -f frontend-deployment.yaml
            kubectl apply -f frontend-service.yaml
          
  3. Exposing the Application to the Internet:

    • Frontend Exposure:

      • The frontend-service is defined with type: LoadBalancer. Kubernetes will provision an AWS Elastic Load Balancer (ELB) for this service.

      • After deployment, retrieve the ELB's public DNS name using:

          kubectl get services
        
      • The EXTERNAL-IP field for frontend-service will show the public DNS name of the ELB. This DNS name allows users to access your web application over the internet.

    • Backend Exposure:

      • The backend-service is also of type: LoadBalancer, but it is generally not exposed directly to the internet. It is intended to be accessed internally by the frontend service. If needed, you can similarly get its external address for testing or other purposes.

Summary:

  1. Set Up Amazon EKS: Create an EKS cluster and configure kubectl.

  2. Deploy Application: Create and apply Kubernetes manifests for your frontend and backend applications.

  3. Expose to the Internet: Use a LoadBalancer Service type for the front end to provision an AWS Elastic Load Balancer (ELB), making the application accessible over the Internet.

By following these steps, you effectively leverage Amazon EKS to manage your Kubernetes deployment and AWS services to ensure your application is scalable and accessible to users.