📌 Question (CKA 2025 — Q-03)

Create a new HorizontalPodAutoscaler (HPA) named apache-server in the autoscale namespace. This HPA must target the existing Deployment called apache-server (in the autoscale namespace).

Requirements:

  • Target 50% CPU usage per Pod.
  • minReplicas: 1, maxReplicas: 4.
  • Downscale stabilization window = 30 seconds.

✅ Manifest — apply directly

cat <<EOF | kubectl apply -f -
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: apache-server
  namespace: autoscale
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: apache-server
  minReplicas: 1
  maxReplicas: 4
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 30
EOF

Notes:

  • autoscaling/v2 is used so we can define the metrics block and behavior.scaleDown.stabilizationWindowSeconds.
  • averageUtilization: 50 means the HPA will aim for ~50% CPU per Pod.