Skip to content

Microservices Platform

Deploy a multi-tier microservices application with a frontend, backend API, worker, Redis queue, and PostgreSQL database.

Time: ~15 minutes Difficulty: Intermediate

Resources: This demo needs ~1GB RAM. Clean up other demos first: task clean:all

  • Decomposing an application into independently deployable services
  • Service-to-service communication inside a Kubernetes cluster
  • Using Ingress to route external traffic to different backends
  • Connecting application pods to databases and caches via environment variables
  • Running background workers that process jobs from a queue
+-----------+
| Ingress |
+-----+-----+
|
+-----------+-----------+
| / | /api
v v
+-----------+ +-----------+
| Frontend | | Backend |
| (nginx) | | API(nginx)|
+-----------+ +-----+-----+
|
+----------+----------+
| |
+-----+-----+ +-----+-----+
| Redis | | PostgreSQL|
| (queue) | | (database)|
+-----+-----+ +-----------+
|
+-----+-----+
| Worker |
| (busybox) |
+-----------+

The Ingress routes / to the Frontend and /api to the Backend API. The Backend connects to PostgreSQL for data storage and Redis for caching and job queuing. The Worker processes jobs from the Redis queue every 10 seconds.

Terminal window
minikube addons enable ingress
Terminal window
kubectl apply -f demos/microservices-platform/manifests/namespace.yaml
kubectl apply -f demos/microservices-platform/manifests/postgres.yaml
kubectl apply -f demos/microservices-platform/manifests/redis.yaml
kubectl apply -f demos/microservices-platform/manifests/backend.yaml
kubectl apply -f demos/microservices-platform/manifests/worker.yaml
kubectl apply -f demos/microservices-platform/manifests/frontend.yaml
kubectl apply -f demos/microservices-platform/manifests/ingress.yaml
Terminal window
kubectl get pods -n microservices-demo -w

Wait until all five pods (postgres, redis, backend, frontend, worker) show Running and 1/1 ready.

Terminal window
# Check all pods are running
kubectl get pods -n microservices-demo
# Check all services
kubectl get svc -n microservices-demo
# Check the ingress
kubectl get ingress -n microservices-demo
# Access the frontend directly
kubectl port-forward svc/frontend 8080:80 -n microservices-demo
# Access the backend API directly
kubectl port-forward svc/backend 8081:80 -n microservices-demo

Open http://localhost:8080 to see the frontend dashboard. Open http://localhost:8081/api/orders to see the API response.

Terminal window
# Watch the worker processing jobs
kubectl logs -f deploy/worker -n microservices-demo
# Verify PostgreSQL has seed data
kubectl exec -it deploy/postgres -n microservices-demo -- \
psql -U orders -d ordersdb -c "SELECT * FROM orders;"
# Verify Redis is reachable
kubectl exec -it deploy/redis -n microservices-demo -- redis-cli PING
manifests/
namespace.yaml # microservices-demo namespace
postgres.yaml # PostgreSQL 16 with init SQL creating orders table + seed data
redis.yaml # Redis 7 as queue and cache
backend.yaml # Nginx returning JSON at /api/health, /api/orders, /api/stats
worker.yaml # Busybox loop simulating job processing every 10 seconds
frontend.yaml # Nginx serving a static HTML dashboard
ingress.yaml # Routes /api to backend, / to frontend

PostgreSQL starts with a ConfigMap-mounted init script that creates an orders table and inserts five sample rows. Redis serves as a lightweight queue and cache. The Backend is an nginx server configured to return JSON responses on API endpoints. The Worker runs a shell loop that logs “Processing job” messages every 10 seconds, simulating a consumer pulling from the queue. The Frontend serves a static HTML page showing the architecture and linking to the API endpoints. The Ingress splits traffic by path so external users reach the correct service.

  1. Scale the backend to handle more traffic:

    Terminal window
    kubectl scale deployment backend --replicas=3 -n microservices-demo
    kubectl get pods -n microservices-demo -l app=backend
  2. Scale the worker to process jobs faster:

    Terminal window
    kubectl scale deployment worker --replicas=2 -n microservices-demo
    kubectl logs -f deploy/worker -n microservices-demo
  3. Add more orders to PostgreSQL:

    Terminal window
    kubectl exec -it deploy/postgres -n microservices-demo -- \
    psql -U orders -d ordersdb -c \
    "INSERT INTO orders (customer_name, product, quantity, status) VALUES ('Frank', 'Sensor F', 10, 'pending');"
  4. Check Redis connectivity from the backend pod:

    Terminal window
    kubectl exec -it deploy/backend -n microservices-demo -- \
    sh -c "apk add --no-cache redis && redis-cli -h redis PING"
  5. Delete the worker pod and watch Kubernetes recreate it:

    Terminal window
    kubectl delete pod -l app=worker -n microservices-demo --wait=false
    kubectl get pods -n microservices-demo -w
Terminal window
kubectl delete namespace microservices-demo

See docs/deep-dive.md for a detailed explanation of microservices decomposition patterns, service discovery in Kubernetes, ingress routing rules, and best practices for connecting services to databases and queues.

Move on to API Gateway to learn how Kong manages routing, rate limiting, and authentication for your APIs.