Amazon EKS — Project 1 — Microservices Application

1 minute read

Project 1 — Microservices on EKS

Build and deploy a 3-tier microservices application with service mesh, ingress, and observability.


Architecture

Microservices Architecture
┌──────────────────────────────────────────────────────┐
│                                                      │
│  Internet                                            │
│     │                                                │
│  ┌──▼────────────┐                                   │
│  │ ALB Ingress   │                                   │
│  │ (HTTPS)       │                                   │
│  └──┬────────────┘                                   │
│     │                                                │
│  ┌──▼──────────┐  ┌──────────────┐  ┌────────────┐ │
│  │ Frontend    │─▶│ API Gateway  │─▶│ Backend    │ │
│  │ (React/Nginx)│  │ (Node.js)   │  │ (Python)   │ │
│  │ 3 replicas  │  │ 3 replicas   │  │ 3 replicas │ │
│  └─────────────┘  └──────┬───────┘  └─────┬──────┘ │
│                          │                 │         │
│                    ┌─────▼─────┐     ┌─────▼─────┐  │
│                    │ Redis     │     │ PostgreSQL│  │
│                    │ (cache)   │     │ (RDS)     │  │
│                    └───────────┘     └───────────┘  │
│                                                      │
└──────────────────────────────────────────────────────┘

Step 1: Create the Cluster

$ eksctl create cluster \
    --name microservices-demo \
    --region us-east-1 \
    --version 1.29 \
    --nodegroup-name standard \
    --node-type t3.medium \
    --nodes 3 \
    --nodes-min 2 \
    --nodes-max 6

Step 2: Deploy Backend

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
  namespace: app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
        - name: backend
          image: myorg/backend:v1
          ports:
            - containerPort: 8000
          env:
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: db-credentials
                  key: url
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 500m
              memory: 512Mi
          readinessProbe:
            httpGet:
              path: /health
              port: 8000
            initialDelaySeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: backend
  namespace: app
spec:
  selector:
    app: backend
  ports:
    - port: 80
      targetPort: 8000

Step 3: Deploy Frontend and API Gateway

Follow the same pattern for frontend (Nginx serving React) and API Gateway (Node.js routing requests).


Step 4: Configure Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  namespace: app
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:...
spec:
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend
                port:
                  number: 80
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-gateway
                port:
                  number: 80

Step 5: Add HPA

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: backend-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: backend
  minReplicas: 3
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          averageUtilization: 70

What You Practiced

  • Multi-service deployment with networking
  • Secrets management
  • ALB Ingress with HTTPS
  • Auto-scaling
  • Readiness probes

What’s Next?

Automate it: Project 2 — CI/CD Pipeline.