This document describes how to test the Horizontal Pod Autoscaler (HPA) functionality for the Restaurant Menu API.
- CPU Target: 70% utilization
- Memory Target: 80% utilization
- Min Replicas: 2
- Max Replicas: 10
- Scale Up: 100% increase every 60 seconds (aggressive)
- Scale Down: 50% decrease every 60 seconds with 5-minute stabilization window (conservative)
- hey - Simple HTTP load testing tool
- Apache Bench (ab) - Classic load testing tool
- k6 - Modern load testing tool with JavaScript
- Artillery - Node.js based load testing
# High concurrent requests to trigger CPU scaling
hey -z 5m -c 50 http://SERVICE_IP/api/menu# Requests that consume memory (e.g., large data operations)
hey -z 5m -c 20 http://SERVICE_IP/api/reservations# Combination of different endpoints
./scripts/test-hpa-scaling.shkubectl get hpa --watchkubectl get pods -l app.kubernetes.io/name=restaurantmenuapi --watchkubectl top pods -l app.kubernetes.io/name=restaurantmenuapikubectl describe hpa restaurantmenuapi- When CPU > 70% or Memory > 80%
- Should add pods within 60 seconds
- Maximum 100% increase per minute
- When CPU < 70% and Memory < 80%
- Should wait 5 minutes before scaling down
- Maximum 50% decrease per minute
- Deploy Application ✅
- Wait for Deployment Ready
- Get Service External IP
- Run Load Test
- Verify Scale Up
- Stop Load Test
- Verify Scale Down
- Assert Test Results
- Pods scale up under load
- CPU/Memory metrics trigger scaling
- Pods scale down after load stops
- Application remains responsive during scaling
- No pod crashes during scaling events
-
Deploy the application
helm upgrade --install restaurantmenuapi ./helm/restaurantmenuapi
-
Get service IP
kubectl get service restaurantmenuapi
-
Run load test
chmod +x scripts/test-hpa-scaling.sh ./scripts/test-hpa-scaling.sh
-
Monitor scaling
# In separate terminals kubectl get hpa --watch kubectl get pods --watch kubectl top pods --watch
- Metrics Server: Ensure metrics-server is installed in cluster
- Resource Requests: Pods must have CPU/Memory requests defined
- LoadBalancer: Service needs external IP for load testing
# Check metrics server
kubectl get deployment metrics-server -n kube-system
# Check pod resource requests
kubectl describe pod <pod-name>
# Check HPA status
kubectl describe hpa restaurantmenuapi