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).
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.
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.
.
├── 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
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:latestOnce 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/Check that pods, services, and HPAs are running:
kubectl get pods
kubectl get svc
kubectl get hpaThe 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- 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
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).
| 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 |
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 |
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- 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
Tommaso Fiorillo Cloud & DevOps Enthusiast ☁️ GitHub • LinkedIn