CKAD field manual

k8s HPA YAML example

HPA adds and removes Pods. It needs metrics-server and a CPU request on the target.

A unit delivers the last crate in a neon jungle and powers down. A unit delivers the last crate in a neon jungle and powers down.
Create
kubectl autoscale deploy web --cpu-percent=70 --min=2 --max=8
YAML
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  minReplicas: 2
  maxReplicas: 8
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
Inspect
kubectl get hpa web
kubectl describe hpa web
kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | head

Fields

scaleTargetRef
The Deployment (or StatefulSet). Kind and name must already exist.
minReplicas
Floor. HPA will not go below this even at idle.
maxReplicas
Ceiling. Without it the object is invalid.
averageUtilization
Percent of the container request, not the limit. No request → HPA cannot compute.
kubectl autoscale
Creates autoscaling/v2 against a live Deployment. Then edit if the question wants memory too.

Watch

  • apiVersion is autoscaling/v2. v2beta2 is gone.
  • averageUtilization is a percent of the request. No CPU request on the Pod → HPA stays unknown.
  • scaleTargetRef must match an existing Deployment (or StatefulSet) name and kind. metrics-server must be running.

Official docs Horizontal Pod Autoscaling

Practice these objects on a live cluster →