1. v2 API
autoscaling/v2 supports multiple and custom metrics, unlike the older v1 CPU-only API.
apiVersion: autoscaling/v2Typorithm · medium
Step 1 of 8 · intro card
Config & Scaling
A HorizontalPodAutoscaler scales a Deployment between minReplicas and maxReplicas to hold a target metric, like averageUtilization 70% CPU, using the autoscaling/v2 API.
An HPA automatically adjusts the replica count of a workload to meet demand, scaling out under load and back in when idle.
scaleTargetRef names the Deployment to scale; minReplicas and maxReplicas bound the range it may use.
metrics with target averageUtilization tell the HPA the goal — it computes desired replicas to keep the observed metric near that value.
autoscaling/v2 supports multiple metrics.
scaleTargetRef names the Deployment.
averageUtilization sets the target.
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: 70Connect each part of the code to the concept before you type.
autoscaling/v2 supports multiple and custom metrics, unlike the older v1 CPU-only API.
apiVersion: autoscaling/v2scaleTargetRef points the HPA at the Deployment whose replica count it adjusts.
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: webThe HPA keeps the replica count between minReplicas and maxReplicas.
minReplicas: 2
maxReplicas: 10averageUtilization: 70 tells the HPA to add or remove pods to keep average CPU near 70%.
target:
type: Utilization
averageUtilization: 70Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.