How nitesh8011/hpa-keda works
Project type and purpose
• This is a Kubernetes‐based event‐driven autoscaling demo that wires up a Spring Boot application (packaged as a JAR and containerized via the Dockerfile) with KEDA (Kubernetes Event‐Driven Autoscaling).
• Its core aim is to show how external metrics (HTTP load, Prometheus metrics, etc.) drive pod scaling through KEDA’s ScaledObject/ScaledJob CRDs.
File structure
• 001_operator/ – Kustomize overlays to install the KEDA Operator (OperatorGroup, Subscription, namespace, CRDs).
• 002_metrics/ – Kustomize overlays for the demo metrics setup:
– ScaledObject.yaml (defines how the Spring Boot Deployment is scaled)
– TriggerAuthentication.yaml (credentials for external metrics sources)
– ServiceMonitor.yaml (Prometheus scrape config)
– RBAC, Secret, namespace, etc.
• Dockerfile & spring-boot-prometheus-grafana-0.0.1-SNAPSHOT.jar – the application image containing Prometheus instrumentation.
• load.yaml – a load generator (e.g., a Job or Pod that pumps HTTP requests) to trigger scaling.
• METRICS.md – documentation on which Prometheus metrics the app exposes.
README for additional insights
• KEDA Operator watches ScaledObject/ScaledJob CRDs and feeds custom metrics to Kubernetes’ HPA.
• The Metrics Server component implements the external metrics API for HPA.
• Scalers (plugins) poll external systems (queue, HTTP endpoint, database).
• When thresholds are met, HPA adjusts replica counts; KEDA can scale to zero.
a. Main components:
– Kubernetes Cluster
– Namespaces: “keda-operator” & “demo-metrics”
– KEDA Operator (Controller)
– KEDA Metrics Server (External Metrics API)
– Scaler plugin(s) (e.g., HTTP request rate scaler)
– Spring Boot Application Deployment (Pods) with Prometheus exporter
– Prometheus Server & ServiceMonitor
– Grafana (optional, for dashboards)
– Horizontal Pod Autoscaler (HPA)
– Load generator (Pod/Job from load.yaml)
– Container image registry (for Dockerfile image)
b. Relationships and data flows:
1. Load generator → sends HTTP requests to Spring Boot Service.
2. Spring Boot pods → expose /metrics; ServiceMonitor → Prometheus scrapes metrics.
3. Scaler plugin queries Prometheus (via TriggerAuthentication Secret).
4. Scaler → provides custom metric to KEDA Metrics Server.
5. KEDA Metrics Server → surface metric through Kubernetes External Metrics API.
6. HPA → fetches metric, adjusts replicas on the Deployment.
7. KEDA Operator → reconciles ScaledObject CRD, ensures HPA is configured correctly and watching the right metric.
c. Architectural patterns/design principles:
– Control loop (Kubernetes Operator pattern)
– Custom Resource Definitions extend Kubernetes API (ScaledObject, TriggerAuthentication)
– Separation of concerns: Operator vs. Metrics Server vs. Scaler vs. HPA vs. Application
– Namespace isolation for operator vs. workloads
d. Key technologies/frameworks:
– Kubernetes CRDs & Operators (Operator SDK)
– Kustomize overlays for environment‐specific configs
– Horizontal Pod Autoscaler with custom/external metrics
– Prometheus & ServiceMonitor (Prometheus Operator)
– Spring Boot with Micrometer/Prometheus exporter
– Docker for container image
– Grafana for visualization