Event-Driven Scaling of Golang Applications in Azure Kubernetes Service (AKS) using KEDA
This article will guide you through setting up event-driven scaling of a Golang application deployed in Azure Kubernetes Service (AKS) using Kubernetes Event-Driven Autoscaling (KEDA). KEDA is an open-source project that provides event-driven autoscaling for Kubernetes workloads.
- Go (version
1.16or later): We’ll use Go to write our publisher and subscriber applications.
- Docker: We’ll use Docker to build and package our Go application.
- Kubernetes CLI (
kubectl): We’ll use kubectl to interact with our Kubernetes cluster.
- Helm: We’ll use Helm to deploy KEDA on our Kubernetes cluster.
Additionally, you’ll need an AKS cluster for deploying our application and KEDA. If you don’t have an AKS cluster ready to use, you can create an AKS cluster by following this Azure documentation.
Table of Contents:
- Deploying KEDA on AKS
- Building a Golang Application for Event-Driven Scaling
- Packaging and Deploying Golang Application in AKS
- Testing Event-Driven Scaling
Deploying KEDA on AKS
We’ll use Helm, a Kubernetes package manager, to deploy KEDA on AKS. Run the following commands to add the KEDA Helm chart repository and install KEDA:
Building a Golang Application for Event-Driven Scaling
Let’s build a simple Golang application that reads messages from an Azure Storage Queue. The number of pods in the deployment will automatically scale up or go scale down based on the number of messages in the Azure Storage Queue. Here’s a simple Go script that reads messages from Azure Storage Queue:
Packaging and Deploying Golang Application in AKS
We need to package our Go application using Docker. Create a
Dockerfile for the same:
After building the Docker image and pushing it to a Docker registry, we create a Kubernetes deployment for our application. However, to enable KEDA, we need to create a
ScaledObject which defines the scaling parameters:
Testing Event-Driven Scaling
To test the event-driven scaling, add messages to the Azure Storage Queue and observe the number of pods of your Golang application. You should see more pods when there are more messages in the queue and fewer pods when there are fewer messages in the queue.
This article walked you through setting up event-driven scaling of a Golang application in Azure Kubernetes Service using Kubernetes-based Event-Driven Autoscaling (KEDA). This capability is crucial in building highly scalable and responsive applications that automatically adjust their resources based on demand.
Subscribe to Faizan Bashir
Get the latest posts delivered right to your inbox