Skip to content

TomFreecss/Text-Sentiment-Analysis-On-Kubernetes-And-EKS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices Application on AWS EKS

Here there is an example of a microservices-based application deployed on AWS EKS (Elastic Kubernetes Service).
It showcases containerization with Docker, orchestration with Kubernetes, and automatic scaling via Horizontal Pod Autoscaler (HPA).


Architecture Overview

The system is composed of three microservices:

Service Description Exposed Port
frontend Simple web interface for user interaction 3000
gateway Backend API gateway that routes requests to the NLP service 8080
nlp Natural Language Processing microservice for text analysis 5000

Each service runs as a Docker container and is deployed on EKS using Kubernetes Deployments, Services, and HPAs.


Infrastructure Diagram


Client → [ LoadBalancer / Ingress ] → [ Frontend Service ]
↓
[ Gateway Service ]
↓
[ NLP Service ]

All components run inside the same Kubernetes cluster on EKS.
The Horizontal Pod Autoscaler (HPA) adjusts the number of pods per deployment based on CPU utilization.


Project Structure


.
├── k8s/
│   ├── deployments/
│   │   ├── frontend-deploy.yaml
│   │   ├── gateway-deploy.yaml
│   │   └── nlp-deploy.yaml
│   ├── services/
│   │   ├── frontend-svc.yaml
│   │   ├── gateway-svc.yaml
│   │   └── nlp-svc.yaml
│   ├── autoscaling/
│   │   └── hpa.yaml
│   └── ingress/
│       └── ingress.yaml
├── docker/
│   ├── frontend/Dockerfile
│   ├── gateway/Dockerfile
│   └── nlp/Dockerfile
├── src/
│   ├── frontend/
│   ├── gateway/
│   └── nlp/
└── README.md


Deployment Instructions

1. Build Docker Images

Each microservice includes its own Dockerfile.
Build and push them to your Amazon ECR repository:

aws ecr create-repository --repository-name frontend
aws ecr create-repository --repository-name gateway
aws ecr create-repository --repository-name nlp

# Example build and push
docker build -t <aws_account_id>.dkr.ecr.<region>.amazonaws.com/frontend:latest ./docker/frontend
docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com/frontend:latest

2. Apply Kubernetes Manifests

Once images are available in ECR, deploy everything to your EKS cluster:

kubectl apply -f k8s/deployments/
kubectl apply -f k8s/services/
kubectl apply -f k8s/autoscaling/hpa.yaml
kubectl apply -f k8s/ingress/

3. Verify Deployment

Check that pods, services, and HPAs are running:

kubectl get pods
kubectl get svc
kubectl get hpa

Autoscaling (HPA)

The file k8s/autoscaling/hpa.yaml defines autoscaling policies for all microservices:

Service Min Pods Max Pods Target CPU Utilization
frontend 2 6 60%
gateway 2 10 60%
nlp 2 8 70%

Ensure the Metrics Server is installed on your cluster:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

Technologies Used

  • AWS EKS – Managed Kubernetes cluster
  • Kubernetes – Deployments, Services, Ingress, Autoscaling
  • Docker – Containerization of each microservice
  • Horizontal Pod Autoscaler (HPA) – Dynamic scaling based on CPU usage
  • Amazon ECR – Private container registry
  • (Optional) Ingress Controller (NGINX / ALB) – Routing to frontend


Environment Variables & Secrets

Before deploying the application or using CI/CD pipelines, make sure to configure the following secrets and environment variables in your GitHub repository (or local .env files).

AWS & EKS Configuration

Variable Description Example
AWS_ACCESS_KEY_ID AWS access key for programmatic access AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY AWS secret access key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
AWS_REGION AWS region where your EKS cluster and ECR repositories are deployed eu-central-1
EKS_CLUSTER_NAME Name of the target EKS cluster eks-ml-api
ECR_REGISTRY ECR registry URL used for Docker image pushes <aws_account_id>.dkr.ecr.<region>.amazonaws.com

GitHub Actions (CI/CD)

If you are using GitHub Actions for automated deployment or image build & push, define these in your repository under
Settings → Secrets and variables → Actions → New repository secret:

Secret Description
AWS_ACCESS_KEY_ID AWS programmatic access key
AWS_SECRET_ACCESS_KEY AWS secret access key
EKS_CLUSTER_NAME Target cluster name used in deployment jobs
AWS_REGION AWS region
ECR_REGISTRY Your ECR registry endpoint

💡 Local Development (Optional)

If you run the services locally using docker-compose or minikube, create a .env file at the project root:

AWS_REGION=eu-central-1
EKS_CLUSTER_NAME=eks-ml-api
ECR_REGISTRY=123456789012.dkr.ecr.eu-central-1.amazonaws.com
FRONTEND_IMAGE=${ECR_REGISTRY}/frontend:latest
GATEWAY_IMAGE=${ECR_REGISTRY}/gateway:latest
NLP_IMAGE=${ECR_REGISTRY}/nlp:latest

Future Improvements

  • Add Prometheus + Grafana for monitoring
  • Implement autoscaling based on memory or custom metrics
  • Add CI/CD pipeline with GitHub Actions
  • Add persistent storage for the NLP service

Author

Tommaso Fiorillo Cloud & DevOps Enthusiast ☁️ GitHubLinkedIn

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors