KEDA Autoscaler
KEDA is a Kubernetes-based Event Driven Autoscaler. With KEDA, you can drive the scaling of any container in Kubernetes based on the number of events needing to be processed. KEDA is a single-purpose and lightweight component that can be added into any Kubernetes cluster. KEDA works alongside standard Kubernetes components like the Horizontal Pod Autoscaler and can extend functionality without overwriting or duplication. With KEDA you can explicitly map the apps you want to use event-driven scale, with other apps continuing to function. This makes KEDA a flexible and safe option to run alongside any number of any other Kubernetes applications or frameworks.
Major wins for KEDA besides the horizontal pod autoscalar in kubernetes are
- Scale to zero which is impossible with HPA
- Lots of metrics that can be used for autoscaling
- Event based autoscalar
KEDA Components
-
Agent - KEDA activates and deactivates Deployments to scale to and from zero on no events. The primary role of
keda-operatorcontainer that runs when KEDA is installed. -
Metrics - KEDA acts as kubernetes metrics server that exposes rich event data like queue length or stream lag to the HPA to drive scale out. It is upto the deployment to consume the events directly from the source. This preserves rich event integration and enables gestures like completing or abandoning queue messages to work out of the box. The metric serving is the primary role of the
keda-operator-metrics-apiservercontainer that runs when you install KEDA.
KEDA CRDs
KEDA creates four CRDs when installed.
-
scaledObjects.keda.sh - represent the desired mapping between an event source (e.g. Rabbit MQ) and the Kubernetes Deployment, StatefulSet or any Custom Resource that defines /scale subresource.
-
scaledjobs.keda.sh - represent the mapping between event source and Kubernetes Job.
-
triggerauthentications.keda.sh & clustertriggerauthentications.keda.sh - ScaledObject/ScaledJob may also reference a TriggerAuthentication or ClusterTriggerAuthentication which contains the authentication configuration or secrets to monitor the event source.
KEDA Installation
KEDA can be installed with helm chart using the following commands.
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
kubectl create namespace keda
helm install keda kedacore/keda --namespace keda
KEDA Scalers
CPU Scalar - Scale applications based on cpu metrics.
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: cpu-scaledobject
namespace: default
spec:
scaleTargetRef:
name: my-deployment
triggers:
- type: cpu
metadata:
type: Utilization
value: "50"
Memory Scaler - Scale applications based on memory metrics.