π From Zero to Kubernetes: A Comprehensive Guide to Deploying NGINX on AWS EKS with Visual Studio Code
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:
π οΈ 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
𧩠Install VS Code Extensions
β’ Open VS Code
β’ Go to Extensions (Ctrl+Shift+X)
β’ Search and install:
"AWS Toolkit"
"Kubernetes"
π 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
π 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
π Configure kubectl β’ In the terminal, run:
aws eks --region us-west-2 update-kubeconfig --name my-cluster
π Verify Connection β’ In the terminal, run:
kubectl get nodes
β’ You should see your cluster nodes listed
π§ 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
π Use Kubernetes Explorer
β’ Click on the Kubernetes icon in the sidebar
β’ Your EKS cluster should appear here
π 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>
π¬ Monitor Deployment
β’ Use the Kubernetes Explorer to view pods, services, etc.
β’ Right-click on resources to get logs, describe resources, etc.
π 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
π 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
π 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
π’ 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
π Update the Application
β’ Edit
deployment.yaml
, change image tonginxdemos/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
π 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)
π§Ή 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
π 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
π§ 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 spujari.devops@gmail.com. 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