DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Kubernetes Tutorial

Introduction to Kubernetes
Kubernetes Architecture
Installing Kubernetes
kubectl Basics
Kubernetes Pods
Kubernetes Deployments
Kubernetes Services
ConfigMaps and Secrets
Kubernetes Storage
Kubernetes Namespaces
Kubernetes Resource Management
Helm for Kubernetes
Kubernetes Monitoring

Horizontal Pod Autoscaler

PreviousPrev
Next

Scale Deployments automatically based on CPU or memory metrics and understand how HPA works with metrics-server.

What Is HPA?

The Horizontal Pod Autoscaler (HPA) changes the number of pod replicas based on observed metrics such as CPU or memory utilization.

Quick Imperative Example

kubectl autoscale deployment web --cpu-percent=70 --min=2 --max=10

YAML Example

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 75

Inspect HPA

kubectl get hpa

How HPA Gets Metrics

HPA commonly reads metrics from metrics-server. Without metrics-server, kubectl top and resource-based autoscaling often do not work.

Cooldown and Stability

Autoscaling should not flap up and down wildly. HPA behavior settings and controller logic help smooth changes over time.

Real-World Example

An API normally runs 2 pods. During peak traffic, average CPU climbs above 70 percent. HPA increases replicas to 6. When load drops and metrics stabilize, it scales back down within the configured bounds.

Why HPA Is Useful

  • improves responsiveness during load spikes
  • reduces manual scaling work
  • can lower cost compared to overprovisioning constantly

HPA is like adding checkout counters in a store when lines get long, then closing extra counters after the rush ends.

Exercise

Scale Direction

What does the Horizontal Pod Autoscaler change?

Exercise

Dependency

Which component is commonly needed for `kubectl top` and basic CPU based HPA metrics?

PreviousPrev
Next

Continue Learning

Kubernetes Namespaces

Organize cluster resources with namespaces, understand built-in namespaces, and apply quotas and limits for multi-team environments.

20 min·Easy

Kubernetes Resource Management

Learn why CPU and memory requests and limits matter before diving into quotas, QoS classes, and autoscaling.

15 min·Easy

Kubernetes Requests and Limits

Set CPU and memory requests and limits, understand throttling and OOM kills, and learn how QoS classes affect pod behavior.

22 min·Easy

Explore Related Topics

Do

Docker Tutorials

Build the containers Kubernetes orchestrates

Te

Terraform Tutorials

Provision Kubernetes clusters as code

Try the Tool

YAML Validator

Validate Kubernetes manifests and any YAML files instantly.

On This Page

What Is HPA?Quick Imperative ExampleYAML ExampleInspect HPAHow HPA Gets MetricsCooldown and StabilityReal-World ExampleWhy HPA Is Useful