{"id":15705,"date":"2024-08-01T13:21:41","date_gmt":"2024-08-01T13:21:41","guid":{"rendered":"https:\/\/47billion.com\/?p=15705"},"modified":"2024-12-23T05:19:48","modified_gmt":"2024-12-23T05:19:48","slug":"developers-insight-navigating-vertical-and-horizontal-pod-autoscaling","status":"publish","type":"post","link":"https:\/\/47billion.com\/blog\/developers-insight-navigating-vertical-and-horizontal-pod-autoscaling\/","title":{"rendered":"Developer’s Insight: Navigating Vertical and Horizontal Pod Autoscaling"},"content":{"rendered":"\n

We’ve been encountering resource shortages in one of our environments, which has led to delays in processing. This issue arises from sudden spikes in load on our RabbitMQ queues, necessitating an increase in workers to handle the queue consumption. <\/p>\n\n\n\n

Our project is centered around Microservices-based architecture and leverages various services, including Celery, RabbitMQ, Redis, MinIO, MongoDB, and Postgres. <\/p>\n\n\n

\n
\"\"<\/figure><\/div>\n\n\n

As the number of task elements queued in RabbitMQ grows, a single worker can\u2019t handle the increased load, which also impacts the resource consumption of individual workers. To address these issues, we use Horizontal Pod Autoscaling (HPA) and Vertical Pod Autoscaling (VPA). <\/p>\n\n\n\n

Previously, this process required significant manual intervention. Developers had to continuously monitor resource usage and manually scale up workers whenever the load increased. This approach was time-consuming and inefficient, diverting valuable developer time and attention from other critical tasks. <\/p>\n\n\n\n

To address these challenges, we turned to Kubernetes’ autoscaling capabilities. By implementing both Vertical Pod Autoscaling (VPA) and Horizontal Pod Autoscaling (HPA), we aimed to create a more resilient and responsive system. VPA adjusts the resource limits of our pods based on actual usage, ensuring that each pod has the necessary CPU and memory to perform efficiently. Meanwhile, HPA dynamically scales the number of pod replicas based on metrics such as CPU utilization or custom metrics like RabbitMQ queue length. <\/p>\n\n\n\n

This dual approach allowed us to handle varying loads more effectively, reduce manual intervention, and improve overall system performance. <\/p>\n\n\n\n

Implementing Vertical Pod Autoscaling (VPA) <\/p>\n\n\n\n

Vertical Pod Autoscaling (VPA) involves monitoring the resource usage of a pod, specifically CPU and memory. To implement VPA, we utilize Kubernetes’ native toolset, which includes the installation of Custom Resource Definitions (CRDs) and several deployments. These components work together to monitor resource usage and automatically adjust the resource limits of your pods, ensuring they have the appropriate amount of CPU and memory based on actual demand. This helps maintain optimal performance and resource efficiency within your Kubernetes environment. <\/p>\n\n\n\n

Installation of CRDs:<\/strong> https:\/\/github.com\/kubernetes\/autoscaler\/tree\/master\/vertical-pod-autoscaler<\/a> <\/p>\n\n\n\n

The above link will help you install the perquisites of Vertical Pod Autoscaling. <\/p>\n\n\n\n

Once you have installed the CRDs, you will now need three major deployments necessary for enabling vertical pod monitoring and autoscaling. <\/p>\n\n\n\n

The three deployments are: <\/strong> <\/p>\n\n\n\n