Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Add an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.

BeginnerHands-onWrite-a-Kubernetes-manifest tasks
Answer
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  minReplicas: 3
  maxReplicas: 15
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70

Key trick → Utilization is a percentage of the container's CPU request, so the HPA shows <unknown> if requests aren't set or metrics-server isn't installed.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks