{"id":269159,"date":"2023-10-05T13:07:01","date_gmt":"2023-10-05T18:07:01","guid":{"rendered":"https:\/\/www.webscale.com\/?p=269159"},"modified":"2023-12-29T15:30:52","modified_gmt":"2023-12-29T20:30:52","slug":"using-the-kubernetes-horizontal-pod-autoscaler-with-prometheus-custom-metrics","status":"publish","type":"post","link":"https:\/\/www.webscale.com\/blog\/using-the-kubernetes-horizontal-pod-autoscaler-with-prometheus-custom-metrics\/","title":{"rendered":"Using the Kubernetes Horizontal Pod Autoscaler with Prometheus\u2019 Custom Metrics"},"content":{"rendered":"

With Kubernetes as the backbone of the CloudFlow Platform, we manage a large, complex network of globally distributed clusters with the goal of optimizing where and when our customers\u2019 workloads are running to suit the needs of their application, while maintaining operational efficiency of the platform.<\/span><\/i><\/p>\n

In order to maximize efficiency, we need a mechanism to dynamically expand and contract resources based on the demands of our customers\u2019 applications at any given time. We rely on the Kubernetes Horizontal Pod Autoscaler (HPA) to scale services in a reliable, predictable, and controllable manner.<\/span><\/p>\n

How the Horizontal Pod Autoscaler Works<\/b><\/p>\n

The HPA controller runs regularly to check if any adjustments to the system are required. <\/span>During each run<\/span><\/a>, the controller manager queries the resource utilization against the metrics specified in each HorizontalPodAutoscaler definition. The controller manager obtains the metrics from either the resource metrics API (for per-pod resource metrics), or the custom metrics API (for all other metrics).<\/span><\/p>\n

\"\"<\/p>\n

The HPA in its basic form is pretty powerful, but where the HPA starts to take on superhero status is when we start to introduce custom metrics to drive autoscaling intelligence.<\/span><\/p>\n

To start, there are three different variables that need to be set before using the HPA. You set these within the HPA configuration itself:<\/span><\/p>\n