# AWS DevOps- Day21

# Kubernetes End-to-End Project on EKS: EKS Installation and App Deployment with Ingress

**Amazon Elastic Kubernetes Service (EKS)** is a fully managed Kubernetes control plane that simplifies the setup of high-availability Kubernetes clusters on AWS. This project walks you through setting up an EKS cluster, deploying an application, and configuring an Ingress controller to manage external traffic to your application.

By the end of this blog, you’ll learn:

1. How to set up an EKS cluster on AWS.
    
2. Install and configure prerequisites on Ubuntu.
    
3. Deploy an application onto the EKS cluster.
    
4. Configure Ingress to manage external access.
    

### **Key Concepts**

1. **EKS vs. Kubernetes:**
    
    * **EKS** simplifies cluster management by handling the control plane, API server, etcd, and scheduler for you.
        
    * Kubernetes offers flexibility for both on-premises and multi-cloud deployments.
        
2. **Ingress Controller:**
    
    * An ingress controller is essential for routing HTTP/HTTPS traffic to your application pods.
        
    * In this demo, we’ll use **AWS ALB Ingress Controller**.
        
3. **IAM Role Integration:**
    
    * IAM roles can be attached to service accounts, enabling pods to securely access AWS services.
        

## **Step 1: Prerequisites Installation on Ubuntu**

Before you begin, ensure you have the necessary tools installed:

### 1\. **Update the system packages**

```bash
sudo apt update && sudo apt upgrade -y
```

### 2\. **Install AWS CLI**

```bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version  # Verify installation
```

### 3\. **Install kubectl (Kubernetes CLI)**

```bash
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client  # Verify installation
```

### 4\. **Install eksctl**

```bash
curl -LO "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz"
tar -xzf eksctl_$(uname -s)_amd64.tar.gz
sudo mv eksctl /usr/local/bin
eksctl version  # Verify installation
```

### 5\. **Install Helm**

```bash
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm version  # Verify installation
```

## **Step 2: Set Up AWS CLI**

### 1\. **Configure AWS CLI**

```bash
aws configure
# Provide:
# AWS Access Key ID: <your-access-key-id>
# AWS Secret Access Key: <your-secret-access-key>
# Default region name: <your-region> (e.g., us-east-1)
# Default output format: json
```

### 2\. **Create an IAM Role for EKS**

Attach the following managed policies to your IAM role:

* **AmazonEKSClusterPolicy**
    
* **AmazonEKSWorkerNodePolicy**
    
* **AmazonEKS\_CNI\_Policy**
    

## **Step 3: Create an EKS Cluster**

### 1\. **Create the EKS Cluster Using eksctl**

```bash
eksctl create cluster \
  --name my-eks-cluster \
  --region us-east-1 \
  --nodes 2 \
  --node-type t3.medium \
  --with-oidc \
  --ssh-access \
  --ssh-public-key <your-ssh-key> \
  --managed
```

The creation process may take several minutes. Once completed, verify the cluster status:

```bash
kubectl get nodes
```

## **Step 4: Deploy an Application**

### 1\. **Create a Namespace**

```bash
kubectl create namespace my-app
```

### 2\. **Deploy the Application**

Create a deployment manifest `deployment.yaml`:

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: my-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: nginx:latest
        ports:
        - containerPort: 80
```

Apply the manifest:

```bash
kubectl apply -f deployment.yaml
```

## **Step 5: Expose the Application**

### 1\. **Create a Service**

Create a service manifest `service.yaml`:

```yaml
apiVersion: v1
kind: Service
metadata:
  name: my-app-service
  namespace: my-app
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: ClusterIP
```

Apply the manifest:

```bash
kubectl apply -f service.yaml
```

## **Step 6: Configure Ingress**

### 1\. **Install NGINX Ingress Controller Using Helm**

```bash
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx --namespace kube-system
```

### 2\. **Create an Ingress Resource**

Create a manifest `ingress.yaml`:

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
  namespace: my-app
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: <your-domain>
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app-service
            port:
              number: 80
```

Apply the manifest:

```bash
kubectl apply -f ingress.yaml
```

## **Step 7: Access the Application**

1. Retrieve the external IP of the load balancer created by the Ingress controller:
    
    ```bash
    kubectl get ingress -n my-app
    ```
    
2. Open the external IP in your browser to access the application.
    

## **Step 8: Troubleshooting Common Issues**

### 1\. **Check Pod Logs**

```bash
kubectl logs <pod-name> -n my-app
```

### 2\. **Describe Resources**

```bash
kubectl describe pod <pod-name> -n my-app
kubectl describe svc my-app-service -n my-app
kubectl describe ingress my-app-ingress -n my-app
```

### 3\. **Check Node and Cluster Status**

```bash
kubectl get nodes
kubectl get events -n my-app
```

### 🏆 **Outcome**

* You now have a fully functional **EKS cluster** hosting a **real-time application**.
    
* The application is accessible via the **ALB Ingress**.
    
* Key Kubernetes concepts like pods, services, and ingress are implemented and tested.
    

### 🤔 **Why Choose EKS?**

* **Managed Service:** Reduces operational overhead.
    
* **Integration:** Seamless AWS service integration via IAM roles.
    
* **Flexibility:** Choose between EC2 and Fargate for worker nodes.
    

### 📚 **Conclusion**

Mastering **EKS** is a must for DevOps engineers. With this hands-on guide, you’ve learned how to deploy a Kubernetes cluster on AWS, expose applications via services, and route traffic using ALB ingress. Keep practicing, as Kubernetes expertise opens doors to exciting opportunities! 🚪🌟

Feel free to share your experience or questions in the comments below! 👇
