Kubernetes is, by default, the container orchestrator for cloud-native applications. However, efficiently doing application scaling in Kubernetes is pretty hard—especially when dealing with event-based kinds of workloads. It’s here that the Kubernetes Event-Driven Autoscaler (KEDA) comes in.
KEDA is an open-source project that gives your applications a dynamic scale-out based on a wide variety of events such as, but not limited to, HTTP requests, messages in a queue, or custom metrics.
Understanding the Core of KEDA
At the heart of KEDA’s functionality lie its core concepts, designed to seamlessly orchestrate the scaling dance of your applications. Here’s a detailed discussion of those concepts:
Event-Driven Autoscaling
Traditional autoscaling mechanisms, while often effective, can sometimes struggle to keep pace with the dynamic nature of event-driven applications. They typically rely on resource metrics like CPU or memory usage to trigger scaling actions. While this approach works well for many scenarios, it might fall short when dealing with applications driven by external events, such as incoming messages or API requests.
This is where KEDA shines, offering a more nuanced and responsive approach to scaling. For deeper insights and sample code, the professionals at DoiT are worth a visit, but the gist is that KEDA shifts the focus from resource metrics to external events, allowing you to scale your applications precisely when and where it’s needed.
Imagine an e-commerce application experiencing a sudden surge in orders during a flash sale. Traditional autoscaling mechanisms might take some time to react to the increased load, potentially leading to performance bottlenecks and frustrated customers. KEDA, on the other hand, can detect this spike in incoming requests and automatically scale up the application to handle the increased load, ensuring a smooth shopping experience for your customers.
Scalers
Scalers are the masterminds behind KEDA’s scaling actions. They define how your application should respond to events, dictating whether it should scale up, scale down, or remain unchanged. (1)
For instance, the CPU scaler can trigger scaling based on CPU utilization, while the memory scaler reacts to memory usage patterns. If you require more specialized scaling behavior, KEDA empowers you to create custom scalers tailored to your specific requirements. This flexibility ensures that KEDA can adapt to a wide range of application architectures and scaling strategies. (1)
Triggers
Triggers act as vigilant sentinels, monitoring various event sources and generating scaling events when predefined conditions are met. They serve as the bridge between the external world and KEDA’s scaling mechanisms.
Whether you’re dealing with HTTP requests, messages in an Azure Service Bus queue, or events from a Kafka topic, KEDA has you covered. This versatility allows you to seamlessly connect your applications to diverse event sources, ensuring that KEDA can respond to the signals that matter most to your scaling decisions.
How KEDA works
KEDA’s magic lies in its ability to seamlessly integrate with the Kubernetes ecosystem, leveraging its existing components to deliver powerful event-driven autoscaling.
KEDA architecture
The KEDA operator is the heart of the system, responsible for managing ScaledObject, which represents the scaling configurations for your applications. It defines the scalers and triggers that KEDA should use to make scaling decisions. On the one hand, the Metrics Server provides KEDA with real-time metrics about your cluster, while the Horizontal Pod Autoscaler (HPA) is the component that actually performs the scaling operations. (2)
This architecture allows KEDA to operate as a lightweight and efficient extension to Kubernetes, adding event-driven autoscaling capabilities without requiring significant modifications to your existing infrastructure.
The Event-Driven Autoscaling Process
In KEDA, an event-driven auto-scaling is an orchestrated series of events. Its very inception is detection. Having intercepted an event from a defined source, the Trigger now contains a scaling signal and will be passed to the KEDA operator. The said operator will look at the ScaledObject associated with the Trigger in order to infer the proper scaling action.
KEDA can then make calculations on wanted amounts of replicas for every event, depending on a Scaler configuration and the real-time state of an application, and control scaling through HPA.
This HPA then manipulates the number of Pods running your application so that extra or decreased load can be handled. This process takes care of scaling issues that may result from a surge in requests or operational demands.
KEDA and Kubernetes
KEDA’s interaction with Kubernetes Deployment and HPA is a testament to its seamless integration with the Kubernetes ecosystem. KEDA leverages the declarative nature of Kubernetes deployments to define the desired state of your application, including its scaling configuration.
Additionally, KEDA helps Kubernetes handle things naturally, allowing events and executions to scale from zero based on demand. This is crucial considering that only 30% of triggers come from HTTPS while the other 70% come from other sources. Hence, deploying KEDA ensures the latter are handled dynamically. (3)
Conclusion
KEDA stands as a testament to the power of innovation in the Kubernetes ecosystem. By embracing the paradigm of event-driven autoscaling, KEDA empowers developers to build highly scalable and resilient applications that can adapt to the dynamic demands of the modern cloud-native landscape.
References:
- “KEDA project adds finesse to Kubernetes autoscaling,” Source: https://www.techtarget.com/searchitoperations/news/252505587/KEDA-project-adds-finesse-to-Kubernetes-autoscaling
- “ScaledObject specification,” Source: https://keda.sh/docs/2.14/reference/scaledobject-spec/
- “Announcing KEDA: bringing event-driven containers and functions to Kubernetes,” Source: https://opensource.microsoft.com/blog/2019/05/06/announcing-keda-kubernetes-event-driven-autoscaling-containers/