advanced

HPA

Autoscale workload replicas from CPU, memory, or custom metrics while respecting readiness and capacity limits.

HPA changes replica count from metrics such as CPU, memory, or custom signals (queue depth, RPS). It absorbs variable load when requests, metrics, and readiness are configured correctly.

					apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 2
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
				

CPU-based scaling needs resource `requests`. Custom metrics need metrics adapters and meaningful business signals.

On interviews: HPA with readiness and cold start latency; database bottlenecks; why autoscaling cannot fix inefficient code alone.

Common pitfalls: missing requests make CPU scaling unreliable; scaling app tier overloads databases or third parties.

The trade-off is elastic capacity versus downstream saturation and cost.

Checklist:

  • Set resource requests on workloads.
  • Scale on meaningful metrics.
  • Check downstream capacity.
  • Pair HPA with cluster autoscaling thoughtfully.