Constructing A Kubernetes App with Amazon EKS

Related Courses

Constructing a Kubernetes App with Amazon EKS

Introduction

Kubernetes has become the go-to solution for managing containerized applications in production environments. Many developers are now moving away from traditional cluster management, as it can be time-consuming and complex. Amazon Elastic Kubernetes Service (EKS) simplifies the process of deploying Kubernetes clusters in the cloud, making it an attractive choice for developers.

Naresh I Technologies, the leading computer training institute in Hyderabad and one of the top five computer training institutes in India, offers comprehensive AWS training, covering all AWS certifications. Contact us today for professional AWS training.

Amazon EKS & Its Benefits

Containers have been in use since the advent of Linux, with Docker emerging as a modern containerization solution. Kubernetes enables efficient deployment and management of containerized applications at scale, ensuring portability and extensibility. However, deploying a Kubernetes cluster manually can be time-intensive due to the need for configuring master-worker nodes. Amazon EKS provides a streamlined solution to this challenge.

Key Advantages of Amazon EKS

  • Managed Kubernetes Service: Amazon EKS eliminates the need to manage the Kubernetes control plane, handling provisioning, patching, and upgrades.

  • Highly Available: It operates across multiple availability zones, ensuring resilience and reliability.

  • Secure Communication: Encrypted communication between worker nodes and the Kubernetes endpoint enhances security.

  • Kubernetes Compatibility: Applications running on EKS are fully compatible with other Kubernetes environments.

  • AWS Integration: Amazon EKS works seamlessly with AWS services and supports native Kubernetes functionalities.

How Amazon EKS Works

Deploying an application with Amazon EKS is straightforward. Follow these steps to set up an EKS cluster:

  1. Create an EKS cluster via the AWS Management Console, CLI, or SDKs.

  2. Deploy worker nodes and integrate them into the EKS cluster.

  3. Use Kubernetes tools to interact with the cluster.

  4. Deploy and manage applications just as you would in any Kubernetes environment.

Now, let’s explore how to deploy a containerized application in a Kubernetes cluster using EKS.

Building a Kubernetes App with Amazon EKS

In this guide, we will deploy an Nginx application on a Kubernetes cluster using EKS. Follow these steps:

Prerequisites

Ensure you have the following:

  • An AWS IAM account with proper permissions.

  • The latest version of AWS CLI installed.

  • AWS IAM authenticator and Kubectl configured.

Step 1: Create an IAM Service Role and VPC

  1. Create an IAM Role:

    • Go to the IAM console.

    • Navigate to "Roles" and click "Create Role."

    • Select "AWS Service" and choose "EKS."

    • Name the role and click "Create Role."

  2. Create a VPC for EKS Deployment:

    • Open AWS CloudFormation.

    • Click "Create Stack."

    • Choose "Specify an Amazon S3 template URL."

    • Review and confirm the details, then create the VPC.

Step 2: Create an EKS Cluster

  1. Open the EKS console and click "Create Cluster."

  2. Provide necessary details, including cluster name, VPC, subnets, security groups, and IAM role.

  3. Click "Create" to launch the cluster.

Step 3: Configure Kubectl for the EKS Cluster

  1. Install Kubectl and the AWS IAM Authenticator.

  2. Set up a kubeconfig file for your cluster:

    aws eks update-kubeconfig --region your-region --name your-cluster-name
  3. Verify the configuration:

    kubectl get svc

Step 4: Deploy and Configure EKS Worker Nodes

  1. Wait for the cluster status to become "Active."

  2. Open AWS CloudFormation and create a stack with the necessary worker node configurations.

  3. Retrieve the worker node Role ARN from the stack outputs.

  4. Create an aws-auth YAML file to allow worker nodes to join the cluster:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: aws-auth
      namespace: kube-system
    data:
      mapRoles: |
        - rolearn: "arn:aws:iam::your-account-id:role/your-node-instance-role"
          username: system:node:{{EC2PrivateDNSName}}
          groups:
            - system:bootstrappers
            - system:nodes
  5. Apply the configuration:

    kubectl apply -f aws-auth.yaml
  6. Check node status:

    kubectl get nodes

Step 5: Deploy an Nginx Application

  1. Create a Kubernetes Deployment YAML file (nginx-deployment.yaml):

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:latest
            ports:
            - containerPort: 80
  2. Apply the deployment:

    kubectl apply -f nginx-deployment.yaml
  3. Expose the deployment with a service:

    kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80
  4. Retrieve the external IP:

    kubectl get svc
  5. Open the IP address in a web browser to view the running Nginx application.

Step 6: Cleanup

After completing the deployment, clean up resources to avoid unnecessary charges:

 
kubectl delete service nginx-deployment
kubectl delete deployment nginx-deployment
aws eks delete-cluster --name your-cluster-name


Conclusion

Congratulations! You have successfully deployed a containerized application on a Kubernetes cluster using Amazon EKS.

Naresh I Technologies is a premier computer training institute in Hyderabad and among the top five in India. We offer in-depth AWS training, covering all certifications. Choose from online or classroom training based on your convenience. We also provide corporate on-premises training and world-class lab facilities. Freshers can benefit from our job placement assistance.

For AWS training inquiries, call us or fill out our online contact form. Our counselors are available to guide you. Start your AWS journey with us today!