Ravindra BagaleCourses & study guides मराठी Track your progress

Guides

Horizontal Pod Autoscaler: Load के नीचे Scale

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.

Quick answer

Hold this vertical picture:

  1. metrics API.
  2. CPU requests.
  3. HPA YAML.
  4. apply; get hpa.
  5. load; watch; cleanup.

Language: English · मराठी · हिंदी

metrics-serverCPU samples HPA objectmin/max + target Load risesUtilization high Replicas upMore pods Load fallsCool down
HPA under load

HPA क्यों

Spike पर ज़्यादा pods.

Why: Fixed replicas = रात बेकार / sale टूटे. 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:

NEED_METRICS_SERVER

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:

requests: {cpu: "100m"}

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:

kubectl get hpa web -w

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.

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.