Day-22-Aws

Mastering Kubernetes with EKS: A Comprehensive Guide to Deploying Applications

TLDR: This blog post provides a detailed overview of deploying applications on AWS Elastic Kubernetes Service (EKS), covering the theoretical concepts, practical steps, and configurations necessary for a successful deployment, including the use of Ingress controllers and Fargate profiles.

In today's fast-paced tech landscape, Kubernetes has emerged as a critical skill for DevOps engineers. This blog post is based on a comprehensive tutorial by Abhishek, focusing on the Elastic Kubernetes Service (EKS) offered by AWS. The aim is to equip aspiring DevOps engineers with the knowledge to deploy real-time applications on EKS, enhancing their resumes and practical skills.

Understanding EKS

What is EKS?

EKS is a managed Kubernetes service that simplifies the deployment and management of Kubernetes clusters on AWS. It abstracts the complexities of setting up and maintaining the control plane, allowing developers to focus on deploying applications.

Why Use EKS?

  1. Managed Control Plane: AWS manages the control plane, ensuring high availability and reliability. This means you don't have to worry about issues like API server downtime or certificate expirations.

  2. Integration with AWS Services: EKS seamlessly integrates with other AWS services, making it easier to manage resources and permissions.

  3. Scalability: EKS supports both EC2 instances and Fargate for worker nodes, allowing for flexible scaling based on application needs.

Key Components of EKS

  1. Control Plane: Managed by AWS, includes components like the API server, etcd, and scheduler.

  2. Data Plane: Consists of worker nodes where applications run. You can choose between EC2 instances or Fargate for this layer.

  3. Ingress Controllers: Manage external access to services within the cluster, routing traffic based on defined rules.

Setting Up EKS

Prerequisites

Before diving into the practical deployment, ensure you have the following tools installed:

  • kubectl: Command-line tool for interacting with Kubernetes clusters.

  • eksctl: Command-line utility for managing EKS clusters.

  • AWS CLI: Command-line interface for AWS services.

Creating an EKS Cluster

To create an EKS cluster, you can use the eksctl command:

eksctl create cluster --name demo-cluster --region us-east-1 --fargate

This command sets up a new EKS cluster with Fargate as the compute option, creating the necessary networking components automatically.

Deploying an Application on EKS

Step 1: Create a Fargate Profile

A Fargate profile allows you to specify which namespaces can run on Fargate. Create a profile for your application:

eksctl create fargateprofile --cluster demo-cluster --name fargate-profile --namespace game2048

Step 2: Deploy the Application

You will deploy a sample application (2048 game) using a deployment configuration. Create a YAML file for the deployment, service, and ingress:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: game2048
  namespace: game2048
spec:
  replicas: 5
  selector:
    matchLabels:
      app: game2048
  template:
    metadata:
      labels:
        app: game2048
    spec:
      containers:
      - name: game2048
        image: your-image-here
        ports:
        - containerPort: 80

Deploy the application using:

kubectl apply -f deployment.yaml

Step 3: Create a Service

To expose your application, create a service:

apiVersion: v1
kind: Service
metadata:
  name: game2048-service
  namespace: game2048
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: game2048

Step 4: Set Up Ingress

To allow external access, configure an Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: game2048-ingress
  namespace: game2048
spec:
  rules:
  - host: your-domain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: game2048-service
            port:
              number: 80

Step 5: Deploy Ingress Controller

To manage the Ingress resource, deploy an Ingress controller (e.g., AWS Load Balancer Controller). This requires setting up an IAM OIDC provider and creating the necessary IAM roles and policies.

Conclusion

Deploying applications on EKS can significantly enhance your DevOps skill set. By leveraging managed services like EKS, you can focus on building and deploying applications rather than managing infrastructure. This guide provides a comprehensive overview of the steps involved in deploying a real-time application on EKS, from setting up the cluster to configuring Ingress for external access.

As you continue your journey in DevOps, mastering EKS will undoubtedly make your resume stand out and prepare you for the challenges of modern cloud-native application development.