This project demonstrates a microservices architecture deployed on Kubernetes with Istio service mesh, featuring automatic sidecar injection, traffic management, circuit breaking, and observability.
The application consists of 4 services running in a Kubernetes cluster with Istio:
┌─────────────────────────────────────────────────────────────┐
│ Kubernetes Cluster │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Frontend Pod │ │ Backend Pod │ │
│ │ ┌──────────┐ │ │ ┌──────────┐ │ │
│ │ │ App │ │ │ │ App │ │ │
│ │ └──────────┘ │ │ └──────────┘ │ │
│ │ │ Sidecar │ │ │ │ Sidecar │ │ │
│ │ │ (Envoy) │ │ │ │ (Envoy) │ │ │
│ │ └──────────┘ │ │ └──────────┘ │ │
│ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │Random-Words │ │ Database Pod │ │
│ │ Pod │ │ ┌──────────┐ │ │
│ │ ┌──────────┐ │ │ │Postgres │ │ │
│ │ │ App │ │ │ └──────────┘ │ │
│ │ └──────────┘ │ │ │ Sidecar │ │ │
│ │ │ Sidecar │ │ │ │ (Envoy) │ │ │
│ │ │ (Envoy) │ │ │ └──────────┘ │ │
│ │ └──────────┘ │ └──────────────┘ │
│ └──────────────┘ │
│ │
│ <--- All traffic flows through sidecars (Envoy) ---> │
│ │
│ Istio Control Plane: Pilot, Mixer, Citadel │
│ - Traffic routing, retries, circuit breaking │
│ - mTLS between services │
│ - Metrics, tracing, logging │
└─────────────────────────────────────────────────────────────┘
- Frontend (port 3000): Web UI serving static files and proxying API requests
- Backend (port 5000): REST API connecting to PostgreSQL
- Random-Words (port 4000): Microservice generating random words
- Database (port 5432): PostgreSQL database with sample data
- Gateway: Ingress gateway for external traffic
- VirtualServices: Route rules for all services with retries and timeouts
- DestinationRules: Load balancing (LEAST_REQUEST, ROUND_ROBIN)
- Circuit Breaking: Connection pool limits and outlier detection
- Retries: Automatic retry with exponential backoff
- Timeouts: Request timeout configuration per service
- Metrics: Prometheus metrics via Envoy sidecars
- Tracing: Distributed tracing with Jaeger
- Logging: Access logs from all sidecars
-
Kubernetes Cluster (Minikube, Kind, or cloud provider)
# Using Minikube minikube start --memory=8192 --cpus=4 -
Istio (version 1.20+)
# Download Istio curl -L https://istio.io/downloadIstio | sh - cd istio-* export PATH=$PWD/bin:$PATH # Install Istio with demo profile istioctl install --set profile=demo -y # Enable automatic sidecar injection kubectl label namespace microservices-lab istio-injection=enabled
-
kubectl configured to connect to your cluster
Build all container images with proper tags:
cd microservices-lab-kube
# Build frontend
docker build -t microservices-lab-frontend:latest ./frontend
# Build backend
docker build -t microservices-lab-backend:latest ./backend
# Build random-words
docker build -t microservices-lab-random-words:latest ./random-wordsFor Minikube: Load images into Minikube's Docker daemon:
minikube image load microservices-lab-frontend:latest
minikube image load microservices-lab-backend:latest
minikube image load microservices-lab-random-words:latestApply all Kubernetes manifests:
# Create namespace with Istio injection enabled
kubectl apply -f k8s/namespace.yaml
# Deploy services
kubectl apply -f k8s/database.yaml
kubectl apply -f k8s/backend.yaml
kubectl apply -f k8s/frontend.yaml
kubectl apply -f k8s/random-words.yaml
# Apply Istio configurations
kubectl apply -f k8s/istio-gateway.yaml
kubectl apply -f k8s/istio-destinationrules.yamlCheck that all pods are running with sidecars injected:
# Check pods (should show 2/2 containers per pod)
kubectl get pods -n microservices-lab
# Check services
kubectl get svc -n microservices-lab
# Check Istio resources
kubectl get gateway,virtualservice,destinationrule -n microservices-labGet the Istio ingress gateway URL:
# For Minikube
minikube tunnel # Run in separate terminal
export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
# Access application
echo "http://$INGRESS_HOST:$INGRESS_PORT"Or port-forward for local access:
kubectl port-forward -n istio-system svc/istio-ingressgateway 8080:80
# Access at http://localhost:8080# Install Kiali
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/addons/kiali.yaml
# Access dashboard
istioctl dashboard kiali# Install Prometheus
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/addons/prometheus.yaml
# Access dashboard
istioctl dashboard prometheus# Install Jaeger
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/addons/jaeger.yaml
# Access dashboard
istioctl dashboard jaeger# Install Grafana
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/addons/grafana.yaml
# Access dashboard
istioctl dashboard grafanaGenerate load to trigger circuit breaker:
# Install fortio load testing tool
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.20/samples/httpbin/sample-client/fortio-deploy.yaml
# Run load test
kubectl exec -n microservices-lab $(kubectl get pod -n microservices-lab -l app=fortio -o jsonpath='{.items[0].metadata.name}') -c fortio -- /usr/bin/fortio load -c 3 -qps 0 -n 30 -loglevel Warning http://backend:5000/apiAdd fault injection to test resilience:
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: backend-fault
namespace: microservices-lab
spec:
hosts:
- backend
http:
- fault:
delay:
percentage:
value: 10
fixedDelay: 5s
route:
- destination:
host: backend
subset: v1
EOF# Check metrics from backend service
kubectl exec -n microservices-lab $(kubectl get pod -n microservices-lab -l app=backend -o jsonpath='{.items[0].metadata.name}') -c istio-proxy -- pilot-agent request GET stats | grep backendRemove all resources:
# Delete application
kubectl delete -f k8s/
# Uninstall Istio
istioctl uninstall --purge -y
kubectl delete namespace istio-system
# Delete namespace
kubectl delete namespace microservices-lab- Traffic Management: Fine-grained control over traffic routing, retries, timeouts
- Security: Automatic mTLS encryption between services
- Observability: Built-in metrics, logs, and distributed tracing
- Resilience: Circuit breaking, outlier detection, fault injection
- Zero Code Changes: All features enabled via configuration, no app code changes
| Feature | Docker Compose | Kubernetes + Istio |
|---|---|---|
| Orchestration | Single host | Multi-node cluster |
| Scaling | Manual | Automatic (HPA) |
| Service Discovery | DNS | DNS + Service mesh |
| Load Balancing | Round-robin | Smart (Least Request, etc.) |
| Circuit Breaking | None | Built-in |
| mTLS | Manual | Automatic |
| Observability | Basic logs | Metrics, traces, logs |
| Traffic Control | Basic proxy | Advanced routing |
- Configure autoscaling with HPA
- Add canary deployments
- Implement A/B testing with traffic splitting
- Set up monitoring alerts
- Configure mutual TLS policies
- Add authorization policies