kuberneteshorizontal-pod-autoscaling

Recommended setting for HorizontalPodAutoscaler's averageUtilization in Kubernetes?


I have a deployment in Kubernetes that takes advantage of HorizontalPodAutoscaler. What are the recommended or typical settings for averageUtilization for CPU and Memory? I'm running a FastAPI and React image within each pod and wanted to know what experiences you all have had in production environments for the averageUtilization setting.

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

My current settings are at 70% for both CPU and Memory thresholds.


Solution

  • If there are no sudden requests on your pod, 70% is a good number. As it may also take time for the additional pods to be ready and existing pods may be fully utilized before the scaled up pods are ready.

    When set to 50, it will scale up faster in the event of a sudden burst requests on your FastAPI and React image.
    Once the scaled up pods are ready, HPA will maintain an average CPU/Memory utilization of the desired percentage (50% or 70%) across all pods.