Horizontal Pod Autoscaler
Definition
The Horizontal Pod Autoscaler (HPA) is a Kubernetes feature that automatically adjusts the number of pods in a deployment, replication controller, or replica set based on observed CPU utilization or other select metrics. It helps maintain application performance and resource efficiency by scaling out or in according to demand, ensuring that the application can handle varying loads without manual intervention.
Secure Settings Example
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: secure-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-secure-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 50
periodSeconds: 60
Insecure Settings Example
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: insecure-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-insecure-app
minReplicas: 0
maxReplicas: 100
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 90