- Pre-Requisites
- Install IBM MQ on Cloud
- Setting up the Sample App
- Optional: Configure message numbers and sleep time
- Installing KEDA
- Running the Demo
- Sample App Limitations
- A docker hub account.
- Docker desktop running with Kubernetes enabled
- Sign Up for an IBM Cloud Account.
- Create an IBM MQ on Cloud instance on your account.
- Follow this guide to:
- Create a Queue Manager
- Register an application
- Generate API and connection credentials
-
Clone the Sample App Repo.
-
Create a
secrets.yamlfile inside thedeployfolder using the following struct:apiVersion: v1 kind: Secret metadata: name: ibmmq-secret type: Opaque data: APP_USER: # Your MQ app username APP_PASSWORD: # Your MQ app password ADMIN_USER: # Your MQ admin username ADMIN_PASSWORD: # Your MQ admin password
-
Replace the
APP_USERAPP_PASSWORDADMIN_USERandADMIN_PASSWORDfields with the corresponding credentials from your MQ application. The values need to be encoded in a Base64 format. -
In the
deploy-producer.yamlanddeploy-consumer.yamlfiles, update the environment variables by supplying theQMGRQUEUE_NAMEHOSTPORTCHANNELandTOPIC_NAMEwith the corresponding credentials from your MQ application.
- You can change the number of messages to send by editing the
argsfield in thedeploy-producer.yamlfile. - You can change the time each consumer sleeps before reading in the next message, this is useful for demonstrating scaling. To change the sleep time (in seconds) edit the
argsfield in thedeploy-consumer.yamlfile.
- Deploy KEDA 2.0.0 from GitHub:
kubectl apply -f https://github.com/kedacore/keda/releases/download/v2.0.0/keda-2.0.0.yaml
-
Apply the secret YAML file:
kubectl apply -f deploy/secrets.yaml -
Run the consumer:
kubectl apply -f deploy/deploy-consumer.yamlThe application should automatically scale to 0, as there are no mesages on the queue. You can confirm this by running
kubectl get hpawhere the number ofreplicasshould be 0. -
Run the producer:
kubectl apply -f deploy/deploy-producer.yaml -
Watch as KEDA scales the consumers to handle the message load:
kubectl get hpa -wThe consumers should scale up to handle the message load, then return to 0 once all of the messages have been consumed from the queue:
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE keda-hpa-ibmmq-consumer Deployment/ibmmq-consumer <unknown>/5 (avg) 1 30 0 0s keda-hpa-ibmmq-consumer Deployment/ibmmq-consumer 64/5 (avg) 1 30 1 61s keda-hpa-ibmmq-consumer Deployment/ibmmq-consumer 4250m/5 (avg) 1 30 4 2m1s keda-hpa-ibmmq-consumer Deployment/ibmmq-consumer <unknown>/5 (avg) 1 30 0 3m2s
This sample supports the basic Put/Get MQ paradigm. If you wish to support more stable message handling and execution involving multiple stages, the transactional support provided by IBM MQ may be of use. Processing is broken down into units of work which are rolled back if errors occur.
If your consumer application has long running or critical processes that would be in danger of termination when scaling down, there are a number of options to guard against this. These include:
- A configurable cooldown period provided by KEDA in which pods will not be terminated even if there are no further messages to be received.
- Graceful termination of pods supported by Kubernetes. This includes grace period settings and container hooks to prevent early termination.
- Scaling of Kubernetes Jobs within KEDA. An individual Kubernetes Job handles each message and will reliably run to completion.