A simple docker container that will receive messages from a RabbitMQ queue and scale via KEDA. The reciever will receive a single message at a time (per instance), and sleep for 1 second to simulate performing work. When adding a massive amount of queue messages, KEDA will drive the container to scale out according to the event source (RabbitMQ).
- Kubernetes cluster
- KEDA 2.0 installed on the cluster
This setup will go through creating a RabbitMQ queue on the cluster and deploying this consumer with the ScaledObject
to scale via KEDA. If you already have RabbitMQ you can use your existing queues.
First you should clone the project:
git clone https://github.com/kedacore/sample-go-rabbitmq
cd sample-go-rabbitmq
Since the Helm stable repositoty was migrated to the Bitnami repository (https://github.com/helm/charts/tree/master/stable/rabbitmq), add the Bitnami repo and use it during the installation (bitnami/ instead of stable/)
$ helm repo add bitnami https://charts.bitnami.com/bitnami
RabbitMQ Helm Chart version 7.0.0 or later
helm install rabbitmq --set auth.username=user --set auth.password=PASSWORD bitnami/rabbitmq
NOTE: With RabbitMQ Helm Chart version 6.x.x or earlier, username and password should be specified with rabbitmq.username and rabbitmq.password parameters https://hub.helm.sh/charts/bitnami/rabbitmq
NOTE: if you are running the rabbitMQ image on KinD, you will run into permission issues unless you set volumePermissions.enabled=true
Use the following command if you are using KinD
helm install rabbitmq --set auth.username=user --set auth.password=PASSWORD --set volumePermissions.enabled=true bitnami/rabbitmq
NOTE: For RabbitMQ Helm Chart version 6.x.x or earlier, refer to the earlier note
RabbitMQ Helm Chart version 7.0.0 or later
helm install --name rabbitmq --set auth.username=user --set auth.password=PASSWORD bitnami/rabbitmq
NOTE: For RabbitMQ Helm Chart version 6.x.x or earlier, refer to the earlier note
kubectl get po
NAME READY STATUS RESTARTS AGE
rabbitmq-0 1/1 Running 0 3m3s
kubectl apply -f deploy/deploy-consumer.yaml
kubectl get deploy
You should see rabbitmq-consumer
deployment with 0 pods as there currently aren't any queue messages. It is scale to zero.
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
rabbitmq-consumer 0 0 0 0 3s
This consumer is set to consume one message per instance, sleep for 1 second, and then acknowledge completion of the message. This is used to simulate work. The ScaledObject
included in the above deployment is set to scale to a minimum of 0 replicas on no events, and up to a maximum of 30 replicas on heavy events (optimizing for a queue length of 5 message per replica). After 30 seconds of no events the replicas will be scaled down (cooldown period). These settings can be changed on the ScaledObject
as needed.