Skip to content

HPA resource metric configuration

HPA resource metric configuration refers to the specific parameters within the metrics field of a Horizontal Pod Autoscaler (HPA) manifest that define how and when scaling occurs based on standard Kubernetes resources like CPU and memory^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md]. This configuration relies on the Metrics Server to provide the necessary data for the autoscaler to make decisions^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

Configuration Structure

In the HPA YAML, resource metrics are defined under spec.metrics with type: Resource^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md]. This type targets the resource usage (specifically CPU or memory) of the pods managed by the scaling target^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80

Key Parameters

  • resource.name: Specifies the metric name, which must be a known Kubernetes resource such as cpu or memory^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].
  • target.type: Defines the specific metric type being tracked. For resource metrics, this must be set to Utilization^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].
  • target.averageUtilization: Sets the target value for the metric, expressed as a percentage of the resource request defined in the Pod specification^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

Implementation Details

When using averageUtilization, the system calculates the average resource usage across all relevant pods and compares it to the target percentage^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md]. For the HPA to function correctly with these metrics, the Pods must have valid resource requests defined in their configuration^[400-devops__06-Kubernetes__k8s-ithelp__Day26__README.md].

Sources