A simple Express.js "ping" server designed to be deployed and scaled on Kubernetes using kind.
- Docker Desktop (running)
- kind (
brew install kindon macOS) - kubectl (
brew install kubectlon macOS) - Node.js and npm
-
Setup the environment:
chmod +x setup.sh deploy.sh fix-metrics-server.sh test-autoscaling.sh ./setup.sh
-
Deploy to kind cluster:
./deploy.sh
-
If metrics server has issues (common with kind):
./fix-metrics-server.sh
-
Test the service:
curl http://localhost:30080/ping
.
├── server.js # Express.js server
├── package.json # Node.js dependencies
├── Dockerfile # Container image definition
├── kind-config.yaml # Kind cluster configuration
├── setup.sh # Environment setup script
├── deploy.sh # Deployment script
├── fix-metrics-server.sh # Metrics server troubleshooting
├── test-autoscaling.sh # Autoscaling load test
└── k8s/
├── deployment.yaml # Kubernetes deployment
├── service.yaml # Kubernetes services
└── hpa.yaml # Horizontal Pod Autoscaler
GET /- Server informationGET /ping- Returns "pong" with server detailsGET /health- Health check endpointGET /stress?duration=5000- CPU stress test for autoscaling (duration in ms, max 30s)
- Min Replicas: 1
- Max Replicas: 15
- CPU Threshold: 60% average utilization
- Memory Threshold: 70% average utilization
- Scale Up: Fast (15s stabilization, up to 100% increase)
- Scale Down: Conservative (60s stabilization, max 50% decrease)
# Make scripts executable
chmod +x test-autoscaling.sh
# Run load test to trigger autoscaling
./test-autoscaling.shThe load test will:
- Generate high-frequency ping requests
- Call CPU stress endpoints
- Monitor scaling in real-time
- Save scaling metrics to
scaling_log.csv
The server automatically scales between 1-15 replicas based on:
- CPU usage > 60%
- Memory usage > 70%
Manual scaling:
kubectl scale deployment ping-server --replicas=5# Watch HPA status
kubectl get hpa ping-server-hpa --watch
# Monitor pod scaling
watch kubectl get pods -l app=ping-server# Check pods
kubectl get pods -l app=ping-server
# Check HPA status
kubectl get hpa ping-server-hpa
# View logs
kubectl logs -l app=ping-server --tail=50
# Port forward for local access
kubectl port-forward svc/ping-server-service 8080:80# Delete deployment only
kubectl delete -f k8s/
# Delete entire kind cluster
kind delete cluster --name ping-server-clusterRun locally for development:
npm install
npm start
# Server runs on http://localhost:3000