Monitoring Horizontal Pod Autoscaling in Kubernetes

Setup Horizontal Pod Autoscaling (HPA)

3 min

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

Exercise Inspect and apply hpa.yaml

Inspect ~/workshop/k3s/hpa.yaml:

bash
cat ~/workshop/k3s/hpa.yaml

This manifest creates an HPA targeting the apache-hpa StatefulSet:

yaml
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-hpa

Once 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:

bash
kubectl apply -f ~/workshop/k3s/hpa.yaml
kubectl get hpa -n apache

Open 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

Exercise Raise maxReplicas to 24 and observe HPA stabilization

Edit the HPA and increase maxReplicas from 4 to 24:

bash
kubectl edit hpa apache-hpa -n apache

Save 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?

Congratulations! You have completed the workshop.

Last Modified ·

Report an issue