Thuta Learning
AdvancedDevOpsintermediate

Scaling & HPA

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Scaling & HPA without feeling intimidated by them
  • Get comfortable running the kubectl commands/YAML yourself
  • Be able to apply this concept immediately in a real project

Let's think about it this way for a second

When traffic spikes, you want more pods — you can manually scale with `kubectl scale deployment web-deployment --replicas=10`, but if nobody scales it back down when traffic drops at midnight, you're just wasting resources. HPA (Horizontal Pod Autoscaler) monitors CPU/memory usage (or a custom metric) and automatically scales pods up when a target threshold is crossed, and back down when usage falls below it — so 'you don't have to babysit scaling yourself.'

Let's connect this to a real scenario

If you create an HPA with something like `kubectl autoscale deployment web-deployment --min=2 --max=10 --cpu-percent=70`, then once average CPU usage crosses 70%, it'll scale pods up to a max of 10, and scale back down to a minimum of 2 once load drops. To run HPA, you need the metrics-server add-on installed on the cluster (it's the component that supplies CPU/memory data).

Let's look at it together

bash
# Manual scale
kubectl scale deployment web-deployment --replicas=10

# Create an HPA: 2-10 pods, target 70% CPU
kubectl autoscale deployment web-deployment \
  --min=2 --max=10 --cpu-percent=70

# Watch HPA in action
kubectl get hpa web-deployment --watch
You should see
NAME              REFERENCE                    TARGETS   MINPODS   MAXPODS   REPLICAS
web-deployment    Deployment/web-deployment    45%/70%   2         10        3

5-Minute Try-It

Create an HPA and watch the target/replicas with `kubectl get hpa --watch` (with no traffic, it'll just sit at the minimum replica count — that's normal).

A Quick Word of Caution

HPA calculates its percentage based on the CPU/memory 'requests' value — if you haven't set resource requests in the Pod spec, HPA won't be able to work properly.

Easy traps

  • Creating an HPA without installing metrics-server first, then running into a 'target unknown' error
  • Setting min/max replicas without accounting for the app's resource constraints (like a database connection limit) — too many pods can exhaust database connections

Now Try It Yourself

Create an HPA and watch the target/replicas with `kubectl get hpa --watch` (with no traffic, it'll just sit at the minimum replica count — that's normal).

You'll know it worked when: NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS web-deployment Deployment/web-deployment 45%/70% 2 10 3

Scaling & HPA | Thuta Learning