The distributed mode can also be deployed on Kubernetes, using Spring Cloud Kubernetes for service discovery instead of Eureka.
Install the following packages:
Create a Kind cluster:
kind create cluster --name microservices# Build all Docker images
docker compose build
# Load images into Kind cluster
for img in simulator quizzes; do
kind load docker-image ${img}:latest --name microservices
done# Create namespace and RBAC
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/rbac.yaml
kubectl apply -f k8s/configmap.yaml
# Deploy infrastructure
kubectl apply -f k8s/infrastructure/rabbitmq.yaml
kubectl apply -f k8s/infrastructure/jaeger.yaml
# Wait for infrastructure to be ready
kubectl wait --for=condition=ready pod -l app=rabbitmq -n microservices-simulator --timeout=120s
kubectl wait --for=condition=ready pod -l app=jaeger -n microservices-simulator --timeout=60s
# Deploy microservices (choose one)
# For stream communication
kubectl apply -f k8s/services-stream/
# For gRPC communication
# kubectl apply -f k8s/services-grpc/
# Check status
kubectl get pods -n microservices-simulatorNote: To change transactional model profile, edit
k8s/services-stream/ork8s/services-grpc/and change theSPRING_PROFILES_ACTIVEenvironment variable of each service.
# Port-forward to gateway
kubectl port-forward svc/gateway 8080:8080 -n microservices-simulator(For all default endpoints including rabbitmq and service discovery, see the Service URLs and Ports section in the main README).
kubectl port-forward svc/jaeger 16686:16686 -n microservices-simulatorThen open http://localhost:16686 to view distributed traces.
kubectl delete namespace microservices-simulatorDeploy the distributed mode to Azure Kubernetes Service for cloud-based deployments.
- Azure CLI installed
- Active Azure subscription (e.g., Azure for Students)
# Login to Azure
az login
# Create Resource Group
az group create --name simulator-rg-es --location spaincentral
# Create AKS Cluster (Free tier, minimal resources) -- This is a cluster example
az aks create \
--resource-group simulator-rg-es \
--name simulator-cluster \
--tier free \
--node-count 1 \
--node-vm-size Standard_B2s_v2 \
--generate-ssh-keys
# Connect to the Cluster
az aks get-credentials --resource-group simulator-rg-es --name simulator-cluster
# Verify connection
kubectl get nodes# Register Container Registry provider (required for ACR)
az provider register --namespace Microsoft.ContainerRegistry
# Check registration status (wait until "Registered")
az provider show --namespace Microsoft.ContainerRegistry --query "registrationState"# Run the push script (creates ACR, attaches to AKS, pushes images)
chmod +x scripts/push-to-acr.sh
./scripts/push-to-acr.sh# 1. Base setup
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/rbac.yaml
# 2. Infrastructure (Centralized PostgreSQL + RabbitMQ)
kubectl apply -f k8s/infrastructure/
# 3. Wait for infrastructure to be ready
kubectl wait --for=condition=ready pod -l app=postgres -n microservices-simulator --timeout=180s
kubectl wait --for=condition=ready pod -l app=rabbitmq -n microservices-simulator --timeout=120s
# 4. Deploy Azure-optimized microservices (uses ACR images + centralized DB)
kubectl apply -f k8s/services-azure/
# 5. Check status
kubectl get pods -n microservices-simulator
# 6. Access the gateway
kubectl get svc gateway -n microservices-simulator
# Or use port-forward
kubectl port-forward -n microservices-simulator svc/gateway 8080:8080Save costs by stopping the cluster when not in use:
# Stop the cluster
az aks stop --name simulator-cluster --resource-group simulator-rg-es
# Start the cluster again
az aks start --name simulator-cluster --resource-group simulator-rg-es# Delete the cluster
az aks delete --name simulator-cluster --resource-group simulator-rg-es
# Delete everything (including ACR)
az group delete --name simulator-rg-esWhen using both local (Kind) and Cloud (Azure) clusters, your kubectl context may be pointing to the wrong cluster.
To see all available clusters:
kubectl config get-contextsTo switch back to your local Kind cluster:
kubectl config use-context kind-microservicesTo switch to your Azure AKS cluster:
kubectl config use-context simulator-cluster