- HPA: scales replica count based on metrics
- VPA: adjusts CPU/memory requests per container (not CKAD)
- KEDA: event-driven autoscaling (not CKAD)
Prerequisites
- Metrics Server must be installed (assume present in exam)
- Target Deployment must have CPU
requests set: without it, TARGETS shows <unknown>/50%
HPA YAML
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: webapp-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: webapp
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
- type: Resource
resource:
name: memory
target:
type: AverageValue
averageValue: 200Mi
Target types
Scaling behaviour
spec:
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 4
periodSeconds: 60
selectPolicy: Min
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1
periodSeconds: 60
Imperative commands
kubectl autoscale deployment webapp --min=2 --max=10 --cpu-percent=60
kubectl autoscale deployment webapp --min=2 --max=10 --cpu-percent=60 \
--dry-run=client -o yaml > hpa.yaml
kubectl: inspect and debug
kubectl get hpa
kubectl get hpa webapp-hpa -o wide
kubectl describe hpa webapp-hpa
kubectl get hpa --watch
Reading kubectl get hpa output
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS
webapp-hpa Deployment/webapp 45%/60%, 180Mi/200Mi 2 10 4
<unknown> → metrics server not running OR CPU requests missing
Troubleshooting
desiredReplicas = ceil(currentReplicas × (currentMetric / desiredMetric))
e.g. 4 replicas at 80% CPU, target 60% → ceil(4 × 80/60) = 6 replicas
Exam gotchas
scaleTargetRef must match exact resource name and kindkubectl describe hpa for scaling events: shows WHY it scaled or didn't- HPA + manual
kubectl scale conflict: HPA overrides manual within a period minReplicas defaults to 1 if not setautoscaling/v2 is current; autoscaling/v2beta2 deprecated