Guides
Horizontal Pod Autoscaler: Load खाली Scale
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
metrics-server, CPU requests, HPA min/max+target, load, replicas वाढ+cool down.
Friends, HPA only works when the pod asks for CPU and metrics-server is alive. Chala mitrano — set maxReplicas so a load test cannot empty the wallet.
मित्रांनो, HPA तेव्हाच चालते जेव्हा pod CPU मागतो आणि metrics-server जिवंत असतो. Chala mitrano — maxReplicas ठेवा.
मित्रों, HPA तभी चलता है जब pod CPU माँगता है और metrics-server जीवित हो। Chala mitrano — maxReplicas रखें।
Quick answer
Hold this vertical picture:
- metrics API.
- CPU requests.
- HPA YAML.
- apply; get hpa.
- load; watch; cleanup.
Language: English · मराठी · हिंदी
HPA under load
HPA का
Spike ला जास्त pods.
Why: Fixed replicas = रात्री वाया / sale ला break.
What: HPA replicas बदलते.
How: CPU resource metric.
Example 1: Confirm metrics-server idea
Type this:
printf '%s\n' 'kubectl get apiservice v1beta1.metrics.k8s.io -o jsonpath="{.status.conditions[0].status}" 2>/dev/null || echo NEED_METRICS_SERVER'
You will see:
What it means: HPA needs metrics-server (or equivalent) before CPU targets work.
Example 2: Deployment with resources
Type this:
mkdir -p /tmp/hpa && printf '%s\n' 'apiVersion: apps/v1' 'kind: Deployment' 'metadata: {name: web}' 'spec:' ' replicas: 1' ' selector: {matchLabels: {app: web}}' ' template:' ' metadata: {labels: {app: web}}' ' spec:' ' containers:' ' - name: web' ' image: public.ecr.aws/docker/library/nginx:1.27-alpine' ' resources:' ' requests: {cpu: "100m"}' ' limits: {cpu: "200m"}' > /tmp/hpa/deploy.yaml && grep -A2 requests /tmp/hpa/deploy.yaml
You will see:
What it means: Requests give HPA a baseline; without them CPU % is meaningless.
Example 3: HPA YAML
Type this:
printf '%s\n' 'apiVersion: autoscaling/v2' 'kind: HorizontalPodAutoscaler' 'metadata: {name: web}' 'spec:' ' scaleTargetRef:' ' apiVersion: apps/v1' ' kind: Deployment' ' name: web' ' minReplicas: 1' ' maxReplicas: 5' ' metrics:' ' - type: Resource' ' resource: {name: cpu, target: {type: Utilization, averageUtilization: 50}}' > /tmp/hpa/hpa.yaml && head -4 /tmp/hpa/hpa.yaml
You will see:
apiVersion: autoscaling/v2
What it means: min/max and CPU target — Flipkart-style web tier pattern.
Concept 1: Apply/watch
Object आधी.
Why: HPA शिवाय load एक pod जाळते.
What: apply; get -w.
How: TARGETS येतात.
Example 4: Apply commands
Type this:
printf '%s\n' 'kubectl apply -f deploy.yaml -f hpa.yaml && kubectl get hpa'
You will see:
kubectl apply -f deploy.yaml -f hpa.yaml && kubectl get hpa
What it means: TARGETS column fills once metrics arrive.
Example 5: Watch HPA
Type this:
printf '%s\n' 'kubectl get hpa web -w'
You will see:
What it means: REPLICAS climbs when utilization stays above the target.
Example 6: Generate load sketch
Type this:
printf '%s\n' 'kubectl run load --rm -it --image=public.ecr.aws/docker/library/busybox:1.36 -- /bin/sh -c "while true; do wget -q -O- http://web/; done"'
You will see:
kubectl run load --rm -it --image=public.ecr.aws/docker/library/busybox:1.36 -- /bin/sh -c "while true; do wget -q -O- http://web/; done"
What it means: Steady traffic — Infosys labs use a loop, not one curl.
Concept 2: Load/events
Traffic + describe.
Why: Events शिवाय अंदाज.
What: busybox loop.
How: Events वाचा.
Example 7: Describe HPA events
Type this:
printf '%s\n' 'kubectl describe hpa web | sed -n "/Events/,+12p"'
You will see:
kubectl describe hpa web | sed -n "/Events/,+12p"
What it means: Events explain why it scaled or stayed put.
Example 8: Scale bounds
Type this:
printf '%s\n' 'minReplicas: 1' 'maxReplicas: 5 # cost ceiling for labs and startups'
You will see:
minReplicas: 1
maxReplicas: 5 # cost ceiling for labs and startups
What it means: Max is a bill guardrail as much as a capacity knob.
Example 9: Cool-down note
Type this:
printf '%s\n' 'After load stops, wait for the stabilization window before replicas drop'
You will see:
After load stops, wait for the stabilization window before replicas drop
What it means: Do not panic if scale-down is slower than scale-up.
Concept 3: Bounds
max = cost cap.
Why: Lab विसरणे महाग.
What: max; delete -f.
How: HPA vs VPA.
Example 10: Custom metric hint
Type this:
printf '%s\n' 'CPU first; custom metrics (queue depth) come after metrics-server works'
You will see:
CPU first; custom metrics (queue depth) come after metrics-server works
What it means: Beginners should prove Resource metrics before custom adapters.
Example 11: Delete lab
Type this:
printf '%s\n' 'kubectl delete -f hpa.yaml -f deploy.yaml'
You will see:
kubectl delete -f hpa.yaml -f deploy.yaml
What it means: Clean labs keep shared clusters tidy.
Example 12: Interview one-liner
Type this:
printf '%s\n' 'HPA changes replica count; VPA changes pod size — different knobs'
You will see:
HPA changes replica count; VPA changes pod size — different knobs
What it means: Amazon/TCS interviews love this contrast.
HPA card
1 metrics-server 2 requests 3 HPA 4 apply 5 load 6 watch
Suppose: unknown targets
Fix metrics-server.
Suppose: no scale
requests + real load.
Ravindra Bagale's Tip
At Flipkart and Amazon interviews, explain: requests give the baseline, target is a percent of that baseline, maxReplicas is the cost ceiling.
Flipkart आणि Amazon interviews मध्ये सांगा: requests = baseline, target = त्याचा percent, maxReplicas = cost ceiling.
Flipkart और Amazon interviews में बताएँ: requests = baseline, target = उसका percent, maxReplicas = cost ceiling।
Check yourself (quiz)
Q1. आधी काय?
metrics-server
Q2. requests?
baseline %
Q3. max?
cost cap
Q4. TARGETS रिकामे?
metrics नाही
Q5. HPA vs VPA?
replicas vs size
Q6. slow down?
stabilization
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
metrics → HPA → load → scale → cool down.
Did you understand? Let us try it once more.
Frequently asked questions
Why unknown on HPA?
Metrics not flowing yet.
Do I need limits?
Requests matter most for HPA %; limits still help fairness.
Custom metrics?
After Resource CPU works.
Will it scale to zero?
Not with default minReplicas 1.
HPA vs Cluster Autoscaler?
Pods vs nodes.
Slow scale-down?
Stabilization — by design.