Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 31/ 160
02. Workload Controllers & Scaling

Horizontal Pod Autoscaler (HPA) & Metrics Server

Scale replicas from CPU/memory metrics via Metrics Server and HPA.

IntermediateHPA · Metrics Server · Autoscale3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

HPA is a restaurant manager opening duplicate counters when each reserved counter stays too busy, rather than merely measuring the queue. The simple Kubernetes rule is: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

Think of it like…

HPA is a restaurant manager opening duplicate counters when each reserved counter stays too busy, rather than merely measuring the queue.

Where you’ve seen it

During a release or scale event, the workload owner runs kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api. Expected evidence: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies. If the run instead shows this symptom, stop and restore the last known state: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.

Words you’ll hear

HPA
For this lesson, HPA is the controlling idea: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.
Metrics Server
Metrics Server is the checkpoint; run kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api and inspect the owner chain. No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.
Autoscale
Autoscale is the outcome to preserve; the cost is explicit: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.
Verification evidence
The evidence command is kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api. It connects the declaration to this behavior: Scale replicas from CPU/memory metrics via Metrics Server and HPA.

Visual diagram

Loading interactive diagram

Theory & deep dive

How HPA reaches the intended state

Scale replicas from CPU/memory metrics via Metrics Server and HPA. HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

The concrete checkpoint is kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api; compare the HPA owner, Metrics Server state, and Autoscale outcome instead of treating YAML acceptance as proof.

Verify Metrics Server, not only object creation

Run kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api after the change and correlate the result with Events and the owning object. HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

Key takeaway: HPA is implemented only when this invariant remains observable: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

Metrics Server: failure boundary and production cost

No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas. The prerequisite contract is concrete: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem. A safe design limits blast radius, records the last good configuration, and uses kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api as a deterministic rollback checkpoint.

Recover from Metrics Server drift

Capture the current state with kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.

Key takeaway: Accept the trade-off consciously: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.

How it works, step by step

Step 1 of 4
Workload author

1. Declare workload intent

Write the controller-owned Pod or scaling intent and preserve the owner chain: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

HPA contract → owned state
Key numbers at this step
Goal
Scale replicas from CPU/memory metrics via Metrics Server and HPA.
Owner
HPA

When to use it & trade-offs

What it is

Scale replicas from CPU/memory metrics via Metrics Server and HPA. HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

Why it matters: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas. The invariant at risk is specific: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies. The quickest fact check before changing the design is kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api.

When to reach for it

  • Use HPA to enforce this invariant: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.
  • Use Metrics Server evidence from kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api in reviews and incident timelines. Scale replicas from CPU/memory metrics via Metrics Server and HPA.
  • Choose the progressive-delivery layer route only when this cost is justified by governance or scale: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.

When to avoid or be careful

  • Avoid assuming HPA is complete after YAML submission; the required behavior is concrete: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.
  • Avoid treating the next symptom as random; check the owner and state with kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api first: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.
  • Avoid adopting a heavier platform wrapper before measuring its cost: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.

Native, manual, and managed paths for HPA

Controller-managed workload
Best for: Scale replicas from CPU/memory metrics via Metrics Server and HPA. A concrete incident check is kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api.

Strengths: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

Watch out: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem. Recovery must also recognize this signal: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.

Hand-managed Pods
Best for: Quickly testing the Metrics Server assumption with kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api; the expected invariant is: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

Strengths: kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api gives immediate feedback without first building a platform layer.

Watch out: A manual change can hide drift, and unlike HPA, it does not make this symptom self-documenting: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.

Progressive-delivery layer
Best for: Teams that need Autoscale integrated with guardrails; the evidence path is kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api.

Strengths: Platform controls can wrap this exact behavior in policy or dashboards: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.

Watch out: The added platform ownership buys value at this cost: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.

Interview signals & numbers to know

When this topic comes up

  • Interview anchor: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.
  • Trace HPA to Autoscale through Metrics Server; the invariant is: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.
  • Recognize the symptom: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.
  • Justify the cost: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.
  • Verify with kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api instead of only inspecting YAML.

Benchmarks & rules of thumb

15s -
default HPA synchronization period
10% -
default utilization tolerance before HPA ignores a small ratio difference
2 -
resource dimensions commonly used are CPU and memory

Common mistakes & follow-ups

Common interview mistakes

  • Debugging only the child object misses the HPA owner contract: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies.
  • Ignoring this telltale condition leads to unrelated changes: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas.
  • Repeating kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api without an owner for remediation wastes retry cost. HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.

Likely interviewer follow-ups

  • How would API output and runtime evidence prove this behavior: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies?
  • Which owner object, logs, and Events would you inspect for this symptom-No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas-?
  • At what threshold would this cost become unacceptable: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem?
Interview tip: Interview sequence: state the invariant, run kubectl get hpa api; kubectl top pods -l app=api; kubectl describe hpa api, name the failure, then justify the cost. Invariant: HPA queries Metrics Server resource metrics, computes a desired replica count from current usage against requested resources, and is stabilized by scaling policies. Failure: No CPU request makes utilization scaling undefined, stale metrics can freeze the controller, and scaling only adds throughput when the bottleneck is inside stateless replicas. Cost: HPA handles demand quickly but duplicates application startup costs and cannot solve a dependency, database, node capacity, or memory limit problem.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Horizontal Pod Autoscaler (HPA) & Metrics Server with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
CronJobs: Scheduled Recurring Tasks & Concurrency Policies
Next topic
Custom & External Metrics Scaling with KEDA (Event-Driven Autoscaling)