πŸš€ From Zero to Kubernetes: A Comprehensive Guide to Deploying NGINX on AWS EKS with Visual Studio Code

πŸš€ From Zero to Kubernetes: A Comprehensive Guide to Deploying NGINX on AWS EKS with Visual Studio Code

Β·

6 min read

This comprehensive guide will take you on a journey from the basics of Kubernetes to deploying a real-world application on Amazon's Elastic Kubernetes Service (EKS). We'll be using Visual Studio Code as our development environment, making the process streamlined and accessible for developers of all levels.

πŸ“ Step-by-Step Guide to Install EKS on Visual Studio Code:

  1. πŸ› οΈ Install Prerequisites

    • β€’ AWS account:

      • Sign up for an AWS account if you don't have one

      • Set up IAM user with necessary permissions (EC2, VPC, IAM, CloudFormation) β€’ AWS CLI:

      • Download and install AWS CLI from the official website

      • Run aws configure to set up your credentials β€’ kubectl:

      • Install kubectl using your system's package manager or download from Kubernetes website

      • Verify installation: kubectl version --client β€’ eksctl:

      • Install eksctl using Homebrew (macOS) or Chocolatey (Windows)

      • For Linux, download the latest release from GitHub

      • Verify installation: eksctl version

  2. 🧩 Install VS Code Extensions

    β€’ Open VS Code

    β€’ Go to Extensions (Ctrl+Shift+X)

    β€’ Search and install:

    • "AWS Toolkit"

    • "Kubernetes"

  3. πŸ”‘ Configure AWS Credentials β€’ Open Command Palette (Ctrl+Shift+P)

    β€’ Type "AWS: Create Credentials Profile"

    β€’ Follow prompts to enter your AWS Access Key ID and Secret Access Key

  4. 🌐 Create EKS Cluster (if not already created)

    β€’ Open a terminal in VS Code β€’ Run:

     eksctl create cluster --name my-cluster --region us-west-2 --nodegroup-name standard-workers --node-type t3.micro --nodes 3 --nodes-min 1 --nodes-max 4 --managed
    

    Now lets check our my-cluster is created in AWS

    As we mention in our command require 3 worker node ,let see 3 worker node is created in our AWS environment or not.

    This process may take 15-20 minutes

  5. πŸ”— Configure kubectl β€’ In the terminal, run:

     aws eks --region us-west-2 update-kubeconfig --name my-cluster
    
  6. πŸ” Verify Connection β€’ In the terminal, run:

     kubectl get nodes
    

    β€’ You should see your cluster nodes listed

  7. 🧭 Explore EKS in VS Code

    β€’ Open the AWS Explorer (AWS icon in the sidebar)

    β€’ Navigate to EKS under your region

    β€’ You should see your cluster listed

  8. πŸ“Š Use Kubernetes Explorer

    β€’ Click on the Kubernetes icon in the sidebar

    β€’ Your EKS cluster should appear here

  9. πŸš€ Deploy to EKS

    β€’ Create a file named deployment.yaml

    β€’ Add a sample deployment:

     apiVersion: apps/v1
     kind: Deployment
     metadata:
       name: hello-app
     spec:
       replicas: 3
       selector:
         matchLabels:
           app: hello
       template:
         metadata:
           labels:
             app: hello
         spec:
           containers:
           - name: hello
             image: nginxdemos/hello
             ports:
             - containerPort: 80
             resources:
               requests:
                 cpu: 100m
                 memory: 128Mi
               limits:
                 cpu: 500m
                 memory: 256Mi
    

    β€’Run below command to apply the deployment file

    β€’ Verify deployment:

     kubectl get deployments
     kubectl get pods
    

    β€’ Check pod details:

     kubectl describe pod <pod-name>
    

  10. πŸ”¬ Monitor Deployment

    β€’ Use the Kubernetes Explorer to view pods, services, etc.

    β€’ Right-click on resources to get logs, describe resources, etc.

  11. 🌐 Create a Service

    β€’ Create a file named service.yaml:

    apiVersion: v1
    kind: Service
    metadata:
      name: hello-service
    spec:
      type: LoadBalancer
      ports:
      - port: 80
        targetPort: 80
      selector:
        app: hello
    

    β€’ This YAML file:

    • Creates a LoadBalancer service

    • Routes external traffic to port 80 of your pods

    • Apply the service:

    kubectl apply -f service.yaml

  1. πŸ” Verify the Service

    β€’ Get service details:

    kubectl get services
    

    β€’ Describe the service:

    kubectl describe service hello-service
    

    β€’ Note the external IP (this may take a few minutes to provision)

    β€’ Check service endpoints:

    kubectl get endpoints hello-service
    

  2. 🌍 Access the Application

    β€’ Open a web browser

    β€’ Enter the external IP of the LoadBalancer service

    β€’ You should see the NGINX demo app

    β€’ Test load balancing by refreshing the page multiple times

  3. πŸ”’ Scale the Application β€’ Scale to 5 replicas:

    kubectl scale deployment hello-app --replicas=5
    

    β€’ Verify scaling:

    kubectl get pods
    kubectl get deployment hello-app
    

    β€’ Watch pods being created:

    kubectl get pods -w
    

  4. πŸ”„ Update the Application

    β€’ Edit deployment.yaml, change image to nginxdemos/hello:plain-text

    β€’ Apply the changes:

    kubectl apply -f deployment.yaml
    

    β€’ Watch the rollout:

    kubectl rollout status deployment/hello-app
    

    β€’ Verify the update:

    kubectl describe deployment hello-app
    

  5. πŸ“Š Monitor the Cluster

    β€’ View cluster info:

    kubectl cluster-info
    kubectl top nodes
    kubectl top pods
    

    β€’ Check pod logs:

    kubectl logs deployment/hello-app
    

    β€’ Set up Prometheus and Grafana for advanced monitoring (optional)

  6. 🧹 Clean Up

    β€’ Delete the service:

    kubectl delete -f service.yaml
    

    β€’ Delete the deployment:

    kubectl delete -f deployment.yaml
    

    β€’ Delete the EKS cluster:

    eksctl delete cluster --name my-cluster --region us-west-2
    

    β€’ Verify deletion in AWS Console:

    • Check EKS, EC2, VPC, and CloudFormation services

  7. πŸ” Additional Security Measures

    β€’ Set up RBAC for your cluster:

    • Create roles and role bindings

    • Use least privilege principle

    • Implement network policies:

    • Install a network policy provider (e.g., Calico)

    • Define ingress and egress rules

    • Use AWS IAM for pod authentication:

    • Create IAM roles for service accounts

    • Associate pods with IAM roles

  8. πŸ”§ Troubleshooting Tips

    β€’ Check pod status: kubectl get pods

    β€’ View pod logs: kubectl logs <pod-name>

    β€’ Describe resources: kubectl describe <resource-type> <resource-name>

    β€’ Check cluster events: kubectl get events --sort-by=.metadata.creationTimestamp

    β€’ Use kubectl exec to run commands inside containers

    β€’ Verify network connectivity between pods

Would you like me to elaborate on any specific part of this expanded guide.

Thank you for joining me on this journey through the world of cloud computing! Your interest and support mean a lot to me, and I'm excited to continue exploring this fascinating field together. Let's stay connected and keep learning and growing as we navigate the ever-evolving landscape of technology.

LinkedIn Profile: https://www.linkedin.com/in/prasad-g-743239154/

Project Details: Github URL-https://github.com/sprasadpujari/Kubernative_Projects/tree/main/AWS_EKS_Setup_Nginx

Feel free to reach out to me directly at . I'm always open to hearing your thoughts and suggestions, as they help me improve and better cater to your needs. Let's keep moving forward and upward!

If you found this blog post helpful, please consider showing your support by giving it a round of applauseπŸ‘πŸ‘πŸ‘. Your engagement not only boosts the visibility of the content, but it also lets other DevOps and Cloud Engineers know that it might be useful to them too. Thank you for your support! πŸ˜€

Thank you for reading and happy deploying! πŸš€

Best Regards,

Sprasad

Β