Kubernetes HPA — Horizontal Pod Autoscaler
Configure horizontal pod autoscaling based on CPU, memory, and custom metrics for Kubernetes workloads.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api-server-hpa
namespace: production
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-server
minReplicas: 2
maxReplicas: 10
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 2
periodSeconds: 60
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 25
periodSeconds: 120
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
- type: Pods
pods:
metric:
name: http_requests_per_second
target:
type: AverageValue
averageValue: 1000Sponsored
DigitalOcean
Use Cases
- Auto-scaling APIs based on traffic load
- Cost optimization with scale-down policies
- Custom metric-driven scaling for high-traffic services
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Kubernetes Deployment Manifest
Production-ready Kubernetes deployment with resource limits, probes, rolling updates, and anti-affinity.
Best for: Deploying containerized applications to Kubernetes
Kubernetes ConfigMap and Secret Management
Create and use ConfigMaps and Secrets for application configuration with env vars and volume mounts.
Best for: Managing application configuration in Kubernetes
Kubectl Rollout — Restart, Status, and Undo
Essential kubectl rollout commands for deployments: restart, status checks, history, and rollback.
Best for: Zero-downtime deployment restarts
Kubernetes CronJob — Scheduled Tasks
Create Kubernetes CronJobs for scheduled tasks with history limits, concurrency control, and deadlines.
Best for: Scheduling daily data exports or reports