Autoscalers in K8s
Horizontal Pod Autoscaler (HPA)
Horizontal Pod Autoscalers (HPAs) provide the ability to scale an application based on a set of criteria. Using metrics such as CPU and memory usage, or your own custom metrics, you can set a rule to scale your Pods up when you need more Pods to maintain your service level.
e.g.
kubectl autoscale deployment nginx --cpu-percent=50 --min=1 --max=5
or
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nginx-deployment
spec:
maxReplicas: 5
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx-deployment
targetCPUUtilizationPercentage: 50