Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Kubernetes, how do I autoscale based on the size of a queue?

Suppose I have a RabbitMQ instance and a set of pods that pick messages from RabbitMQ and process them. How do I make Kubernetes increase the number of pods as the queue size increases?

(I'm mentioning RabbitMQ, but that's just an example. Pick your favorite message queue software or load balancer if you wish.)

like image 522
Likk Avatar asked May 22 '16 17:05

Likk


People also ask

How does auto scaling work in Kubernetes?

In Kubernetes, a HorizontalPodAutoscaler automatically updates a workload resource (such as a Deployment or StatefulSet), with the aim of automatically scaling the workload to match demand. Horizontal scaling means that the response to increased load is to deploy more Pods.

Does Kubernetes support auto scaling?

Kubernetes enables autoscaling at the cluster/node level as well as at the pod level, two different but fundamentally connected layers of Kubernetes architecture. "You can't scale the application if there's no capacity remaining in the cluster."

Does Kubernetes handle scaling?

Kubernetes supports auto scaling of both control plane and worker nodes for optimum performance handling. With inherent cluster scaling capabilities, Kubernetes allows increasing or reducing the number of nodes in the cluster based on node utilization metrics and the existence of pending pods.


2 Answers

The top-level solution to this is quite straightforward:

Set up a separate container that is connected to your queue, and uses the Kubernetes API to scale the deployments.

There exist some solutions to this problem already, but they do however not look like they are actively maintained and production ready, but might help:

  • https://github.com/mbogus/kube-amqp-autoscale
  • https://github.com/mbogus/docker-kube-amqp-autoscale
  • https://github.com/onfido/k8s-rabbit-pod-autoscaler
like image 148
Kenneth Lynne Avatar answered Sep 27 '22 21:09

Kenneth Lynne


You can use KEDA.

KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes

It supports RabbitMQ out of the box. You can follow a tutorial which explains how to set up a simple autoscaling based on RabbitMQ queue size.

like image 25
Azatik1000 Avatar answered Sep 27 '22 19:09

Azatik1000