So, what actually is keda?
So, Keda or, Kubernetes-based Event Driven Autoscaler is a way for you to drive the scaling of any container in your kubernetes cluster based on a number of events (in my case messages on a RabbitMQ queue). This is achieved by two custom resources: ScaledObjects and TriggerAuthentication. You create a YAML file that defines what to listen to and when. It then allows you to set parameters for the scaling. It then creates an HPA (horizontal pod autoscaler) that will then scale you pod based on the information provided in the YAML file.
Basically you create some resources called ScaledObject, this then listens at the defined interval to your message queue for example and when your set parameters are met it will either scale up or down your pods. One good thing about this is you can scale all the way down to 0!
You can read more about Keda on their website https://keda.sh/
How to deploy Keda
There are a couple of ways to install Keda. Helm charts and YAML files. I personally choose to use the Yaml file method. This is mostly due to a bad experience with Helm 2 and the use of Tiller. That has now been resolved in Helm 3 so I may switch at some point.
Deploying with YAML and kubectl
For this, you will need to clone and download the keda repo. The repo can be found at https://github.com/kedacore/keda. You will find the YAML files in the /deploy directory. Feel free to review and edit them to fit your needs or just go ahead and deploy them.
So in your terminal navigate to a folder that you have downloaded the repo to and make sure you are connected to the Kubernetes cluster you would like to deploy Keda to.
First, you will need to create a namespace called keda.
1 |
kubectl create namespace keda |
Now the actual deployment.
1 2 3 |
kubectl apply -f deploy/crds/keda.k8s.io_scaledobjects_crd.yaml kubectl apply -f deploy/crds/keda.k8s.io_triggerauthentications_crd.yaml kubectl apply -f deploy/ |
Deploying with Helm
For this you will need Helm installed you can find out how to do that at https://helm.sh/docs/intro/install/. I would highly recommend you go with Helm 3.
First, you will need to add the Helm repo. This will add the keda helm repo to your list of repos.
1 |
helm repo add kedacore https://kedacore.github.io/charts |
Now you will need to update the helm repo. This will download the latest charts from the helm repos.
1 |
helm repo update |
Helm 2
To deploy with helm 2 you can use the following command.
1 |
helm install kedacore/keda --namespace keda --name keda |
I do not have helm 2 installed so will be unable to share a picture.
Helm 3
To deploy using helm 3 use the following. You will notice you have to create the keda namespace first using kubectl.
1 2 |
kubectl create namespace keda helm install keda kedacore/keda --namespace keda |
You have now installed keda using helm
Check the deploy
To check that everything has deployed you can use the following command. You should see that all pods, services, deployments and replica sets are up and running. If you have any issues, it would be wise to uninstall and try again. Failing that reach out at the Git Repo.
How to remove Keda
The YAML way
As with deploying keda, you will need to be in the same directory that you have cloned from the GitHub repo. You will then need to use the following commands to delete the deployed resources.
1 2 3 |
kubectl delete -f deploy/crds/keda.k8s.io_scaledobjects_crd.yaml kubectl delete -f deploy/crds/keda.k8s.io_triggerauthentications_crd.yaml kubectl delete -f deploy/ |
Now to clear things up you can remove the namespace by using the following.
1 |
kubectl delete namespace keda |
The Helm way
If you have helm 2 then use this.
1 2 3 |
helm delete --purge keda kubectl delete -f https://raw.githubusercontent.com/kedacore/keda/master/deploy/crds/keda.k8s.io_scaledobjects_crd.yaml kubectl delete -f https://raw.githubusercontent.com/kedacore/keda/master/deploy/crds/keda.k8s.io_triggerauthentications_crd.yaml |
If you have used helm 3 then use this.
1 2 3 |
kubectl delete -f https://raw.githubusercontent.com/kedacore/keda/master/deploy/crds/keda.k8s.io_scaledobjects_crd.yaml kubectl delete -f https://raw.githubusercontent.com/kedacore/keda/master/deploy/crds/keda.k8s.io_triggerauthentications_crd.yaml kubectl delete namespace keda |
Summary
So above I have explained what keda is, how to install it using YAML files and helm. I have also shown you how to check if the deployment has been successful and also how to remove it. I am currently using keda for all of my kubernetes scale needs as I am using RabbitMQ as my message broker. In another article, I will go through the steps needed to get keda to auto-scale based on a RabbitMQ queue size.
Until then, if you have any questions or comments please leave them below or reach out in the usual ways.
1 Comment
Nilesh · October 20, 2020 at 1:53 am
This is a great introduction to KEDA. Readers of this blog might find this 3 part Youtube video series on KEDA helpful
https://www.youtube.com/playlist?list=PLOPXEdTIaFO8D73ufHmoGCauRRhCy5uBh
There is also an interesting video on using KEDA along with Azure Container Instances (ACI) to make use of Serverless capabilities. This uses the Virtual Node to schedule workloads on serverless infrastructure.
https://www.youtube.com/watch?v=9_rxGygUH1Y&t=293s