Kubernetes YAML Workloads/HorizontalPodAutoscaler YAML

Scale Deployment based on CPU utilization.

Section: Autoscaling and Availability

HorizontalPodAutoscaler YAML

yaml
yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Autoscaling and Availability
PodDisruptionBudget YAML
Protect minimum availability during voluntary disruption.
OpenIn sheetyamlsame section
Basic StatefulSet YAML
Run stateful replicas with stable ordinals.
Basic DaemonSet YAML
Deploy a log collector or node agent everywhere.
Basic Job YAML
Run a one-time batch task with retries.
Set rolling update partition
Control StatefulSet ordinal rollout.
Restart a DaemonSet rollout
Trigger rollout after a config change.