KEDA Autoscaling with Nginx
A demonstration of Kubernetes Event-Driven Autoscaling (KEDA) with Nginx deployment, featuring automated load testing and real-time scaling monitoring.
๐ Overview
This project demonstrates horizontal pod autoscaling using KEDA based on CPU utilization. The setup automatically scales an Nginx deployment between 3-10 replicas when CPU usage exceeds 40%.
๐ Features
- CPU-Based Autoscaling: Scales based on 40% CPU utilization threshold
- Configurable Replica Range: 3 minimum, 10 maximum pods
- Intelligent Cooldown: 30-second cooldown period between scaling events
- Load Testing Script: Python-based concurrent load generator
- Real-Time Monitoring: Live pod count and request distribution tracking
- Even Load Distribution: Kubernetes service ensures balanced traffic across pods
๐ Configuration
KEDA ScaledObject (nginx-scaler.yaml)
Key Parameters
| Parameter | Value | Description |
|---|---|---|
minReplicaCount |
3 | Minimum number of pods |
maxReplicaCount |
10 | Maximum number of pods |
cooldownPeriod |
30s | Wait time before scaling down |
pollingInterval |
10s | Frequency of metric checks |
cpu.value |
40% | CPU threshold for scaling |
๐ฆ Baseline Setup
Initial Deployment State
Before load testing, the environment was configured with:
Pods (3 replicas at minimum):
Service (LoadBalancer):
The LoadBalancer exposes Nginx at 10.10.10.50:80, which serves as the target for load testing.
๐งช Load Testing
Running the Test
Arguments:
http://10.10.10.50- Target URL240- Duration in seconds200- Concurrent users
Real-Time Scaling Events
The load test script monitors pod scaling in real-time:
Scaling Behavior
The test demonstrates effective autoscaling:
- Initial State: 3 pods
- Scaling Trigger: CPU utilization exceeded 40% threshold
- Scale Up Time: 35 seconds (3 โ 6 pods)
- Requests at Scale Event: 17,923 requests processed
- Final State: 6 pods maintained throughout test
- Load Distribution: Even distribution across all pods (~15k-21k requests per pod)
Test Results
๐ Pod Distribution
Traffic was evenly distributed across scaled pods:
๐ Monitoring Commands
Check HPA Status
Output:
Watch Pods Scale
View Current Pods
๐ ๏ธ Setup
Prerequisites
- Kubernetes cluster
- KEDA installed (installation guide)
- kubectl configured
- Python 3.x with
uv(for load testing)
Installation
-
Deploy the ScaledObject:
-
Verify KEDA Configuration:
-
Check HPA Creation:
๐ก Key Insights
- Responsive Scaling: Pods scaled up in 35 seconds under load
- Load Balancing: Kubernetes service distributed ~108k requests evenly
- Stability: 99.88% success rate (107,702/107,830 requests)
- Performance: Sustained 428 requests/second with 200 concurrent users