The Kubernetes controller that automatically scales the number of Pod replicas in a Deployment, ReplicaSet, or StatefulSet based on observed CPU, memory, or custom metrics. The primary production autoscaling tool and a core CKA topic. Synthesized from CKA Day 17 — Kubernetes Autoscaling Explained.
What Is HPA?
HPA is a control loop that runs inside the kube-controller-manager. It periodically queries metrics (via the Metrics Server or custom metrics APIs), compares them against user-defined targets, and adjusts the replicas field of a target workload.
HPA then updates the Deployment’s spec.replicas to 4. The Deployment controller creates the additional Pods, and the Service’s Endpoints list updates automatically.
Metric Types
Type
What It Measures
Example Target
Resource
Pod-level CPU or memory
averageUtilization: 50
Pods
Custom metric averaged per Pod
Pods per second per replica
Object
Metric from a Kubernetes object (e.g., Ingress requests/sec)
Requests per second
External
Metric from an external monitoring system (e.g., Prometheus, CloudWatch)
Queue depth
For the CKA exam, Resource metrics (CPU and memory) are the most relevant.
Scale Behavior and Stabilization
By default, HPA:
Scales up immediately when thresholds are exceeded (no delay)
Scales down gradually after a 5-minute stabilization window to avoid flapping
This says: scale up as fast as needed (double replicas every 15s), but scale down no more than 1 Pod every 2 minutes, and wait 5 minutes of low load before scaling down at all.
Imperative Commands (CKA Speed Patterns)
# Create HPA for a Deployment (fastest exam method)kubectl autoscale deployment nginx-deploy --min=1 --max=10 --cpu-percent=50# Create HPA with memory targetkubectl autoscale deployment nginx-deploy --min=1 --max=10 --cpu-percent=50# Then edit the generated YAML to add memory metrics# Check HPA statuskubectl get hpakubectl describe hpa nginx-hpa# View HPA events for troubleshootingkubectl get events --field-selector involvedObject.name=nginx-hpa# Delete HPAkubectl delete hpa nginx-hpa
CKA Tip:kubectl autoscale generates a valid autoscaling/v2 HPA manifest. Use --dry-run=client -o yaml to generate and customize before applying. Source: CKA Day 17
Troubleshooting Matrix
Symptom
Likely Cause
Diagnostic Command
Fix
HPA shows <unknown>
Metrics Server missing or not ready
kubectl get pods -n kube-system | grep metrics
Install Metrics Server
HPA shows 0/0
No resources.requests in Pod template
kubectl get deploy <name> -o yaml | grep requests
Add CPU/memory requests
HPA does not scale up
Target already at maxReplicas
kubectl get hpa
Raise maxReplicas or investigate load
HPA scales but Pods stay Pending
Cluster has no available node capacity
kubectl get nodes
Add nodes or use Cluster Autoscaler
Scale flapping (up/down repeatedly)
Stabilization window too short
kubectl describe hpa
Increase stabilizationWindowSeconds
Service not routing to new Pods
Selector mismatch or readiness probe failing
kubectl get endpoints
Verify labels and readiness probes
HPA and Services
When HPA adds Pods, the target workload’s labels are already correct (inherited from the template). The Service’s selector matches those labels, and the Endpoints controller adds the new Pod IPs automatically. Clients using the Service never notice the scaling event. Source: CKA Day 9
HPA and Resource Requests
HPA is the primary consumer of the resources.requests declared in Day 16. The entire utilization percentage is computed relative to the request:
CPU% = (measured CPU millicores) / (requested CPU millicores) * 100
If a container requests 100m and is using 80m, HPA sees 80% utilization. If the target is 50%, HPA scales up. This is why under-provisioning requests (e.g., 1m) causes premature scaling, and over-provisioning (e.g., 2000m) prevents scaling entirely. Source: CKA Day 16
Exam-style hands-on tasks for this topic. Complete each task before reviewing the solution. Time yourself — CKA tasks average 5–7 minutes.
Task 1: Create an HPA with Specific Target
You are asked to create HPA web-hpa for Deployment web with target CPU 70%, min 3, max 15.
Requirements: Use autoscaling/v2 YAML or kubectl autoscale then edit.
Verification:kubectl get hpa web-hpaSolution:
kubectl autoscale deployment web --name=web-hpa --cpu-percent=70 --min=3 --max=15
Task 2: Interpret HPA Status
You are asked to check HPA status and explain the TARGETS column.
Requirements: Use kubectl get hpa and kubectl describe hpa.
Verification: Output shows current/target percentage (e.g., 45%/70%).
Solution:
kubectl get hpa web-hpakubectl describe hpa web-hpa# TARGETS shows (currentMetric / desiredMetric).# If it shows <unknown>, Metrics Server is missing or requests are not set.
Task 3: Fix an HPA Showing <unknown>
An HPA shows <unknown> in the TARGETS column.
Requirements: Determine whether Metrics Server is missing or the Deployment lacks resource requests, then fix it.
Verification:kubectl get hpa shows a numeric target.
Solution:
# Check Metrics Serverkubectl get pods -n kube-system | grep metrics-server# Check Deployment requestskubectl get deployment web -o yaml | grep -A 5 resources# Install Metrics Server if missing, or add CPU requests to the Deployment template.