Monitoring Horizontal Pod Autoscaling in Kubernetes
Setup Horizontal Pod Autoscaling (HPA)
In Kubernetes, a HorizontalPodAutoscaler automatically updates a workload resource (such as a Deployment or StatefulSet) to scale the number of Pods to match demand.
Horizontal scaling responds to increased load by adding more Pods. This differs from vertical scaling, which assigns more CPU or memory to existing Pods.
When load decreases and the replica count is above minReplicas, the HorizontalPodAutoscaler scales the workload back down.
1. Setup HPA #
Inspect ~/workshop/k3s/hpa.yaml:
cat ~/workshop/k3s/hpa.yamlThis manifest creates an HPA targeting the apache-hpa StatefulSet:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: apache-hpa
namespace: apache
spec:
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
averageUtilization: 50
type: Utilization
- type: Resource
resource:
name: memory
target:
averageUtilization: 75
type: Utilization
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: StatefulSet
name: apache-hpaOnce applied, apache-hpa autoscales between 1 and 4 pods whenever average CPU utilization exceeds 50% of its request (500m) or average memory utilization exceeds 75% of its request (16Mi).
Apply the HPA and check its status:
kubectl apply -f ~/workshop/k3s/hpa.yaml
kubectl get hpa -n apacheOpen the Workloads or Node Detail tab in Kubernetes Navigator and watch apache-hpa scale out (apache-hpa-1, apache-hpa-2, apache-hpa-3), then check how throughput changes in the Apache web servers (OTel) Navigator.
2. Increase the HPA replica count #
Edit the HPA and increase maxReplicas from 4 to 24:
kubectl edit hpa apache-hpa -n apacheSave and exit (Esc, then :wq!). Wait 2–3 minutes for the HPA to scale out and for metrics to update in Splunk Observability Cloud, then check kubectl get hpa -n apache, kubectl get pods -n apache, and the HPA view in Kubernetes Navigator.
Quick check
After raising maxReplicas to 24, why does the HPA stop scaling before reaching all 24 replicas?
loadgen is distributed across more apache-hpa pods until average CPU utilization settles near the 50% target — so the HPA stops scaling once demand is met instead of blindly consuming all 24 replicas. On a smaller cluster with less allocatable CPU, pods beyond what the nodes can fit remain in Pending until capacity is added or load drops.Congratulations! You have completed the workshop.
