Event-driven Autoscaling
through KEDA and
Knative Integration
Daniel Oh
Senior Principal Developer Advocate
2
About Me
Daniel Oh
● Senior Principal Technical Marketing Manager at Red Hat
○ Cloud Native Runtimes
○ Serverless and Service Mesh practices
● Ambassador for CNCF and DevOps Institute
● Advisory Board Member of Global Skill Development Council
● Opensource.com Correspondents
● Public Speaker & Developer Advocate
● Published Author
○ Practical Ansible 2
○ Quarkus for Spring Developers
danieloh30
@danieloh30
bit.ly/danielohtv
3
Autoscaling Architecture on Kubernetes
4
Autoscaling Architecture on Kubernetes w/ External Services
5
6
7
● Project aims to make Kubernetes Event Driven Autoscaling dead simple
● Started as a partnership between Red Hat and Microsoft (Feb 2019)
● Donated into CNCF as a Sandbox project (Mar 2020)
● KEDA 2.0 brought major redesign (Nov 2020)
● Promoting to CNCF Incubation project (Aug 2021)
● KEDA 2.6 has been released recently (Feb 2022)
● https://keda.sh
8
● Automatically scale Kubernetes Deployments, Jobs & Custom Resources
● Provides 49+ built-in scalers, but users can build own external scalers
○ Kafka, Prometheus, RabbitMQ, AWS services, Azure Services,...
● Scale resources based on events in the target scalers, eg. messages in
Kafka topic
● KEDA does not manipulate the data, just scales the workload
● Installation through OLM Operator or Helm
https://keda.sh/docs/2.6/scalers/
9
10
How does KEDA works?
● KEDA is built on top of Kubernetes
● Use ScaledObject/ScaledJob to
define scaling metadata
● Manages workloads to scale to 0
● Registers itself as k8s Metric Adapter
● Provides metrics for Horizontal Pod
Autoscaler (HPA) to scale on
11
ScaledObject
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: example-so
spec:
scaleTargetRef:
name: example-deployment
minReplicaCount: 0
maxReplicaCount: 100
triggers:
- type: kafka
metadata:
bootstrapServers: kafka.svc:9092
consumerGroup: my-group
topic: test-topic
lagThreshold: '5'
● Can target Deployment, StatefulSet or
Custom Resource with scale
● Multiple scalers can be defined as
triggers for the target workload
● User can specify HPA related settings
to tweak the scaling behavior
12
How about Serverless
Autoscaling?
13
14
● Operates on standard k8s resources
● Can scale existing deployed apps
● Pull based approach
● Doesn’t manage data delivery
● K8s Horizontal Pod Autoscaler (HPA)
● Focus is on event driven autoscaling
● Operates on Knative Service
● Existing apps must be converted
● Push based approach
● Manages data delivery (Eventing)
● Knative Autoscaler
● Demand-based autoscaling (HTTP)
15
Use Case #1
Application consuming messages from Kafka topic
● Application is deployed as
standard Kubernetes Deployment
● Can be autoscaled only via
standard k8s HPA: CPU & Memory
● No event-driven autoscaling
Kubernetes
Deployment
Application
Consumes
messages
#Demo
17
● Application remains the same and is being
deployed the same way
● Event-driven autoscaling enabled through
KEDA
Scales
Kubernetes
Deployment
Application
Consumes
messages
Scrapes
metrics
Kubernetes
Deployment
Application
Kubernetes
Deployment
Application
Use Case #2
Redesigned to utilize KEDA
#Demo
19
● Application needs to be rewritten from Kafka
consumer to CloudEvents consumer
● Application needs to be redeployed as Knative
Service
● Needs Knative Eventing Kafka Source
● Event-driven autoscaling enabled through
Knative Autoscaler
Consumes
messages
Knative
Eventing
Kafka Source
Knative
Service
Application
Sends
CloudEvents
Monitors load
&
scales
Knative
Service
Application
Knative
Service
Application
Use Case #3
Redesigned to utilize Knative
#Demo
21
How about Serverless
Autoscaling?
Event-driven
22
Integrate KEDA with
Knative
23
● KEDA can be used to autoscale Knative Eventing Infrastructure
○ Knative Eventing Sources, Channels
○ Autoscaling allows infrastructure to handle higher loads or save
resources (by scaling to 0) when idle
● KEDA could be potentially used to scale Knative Service, in case users
don’t want to utilize Knative Eventing for event driven workloads
(currently not implemented)
KEDA and Knative Integration
24
● Application deployed as Knative
Service and autoscaled by Knative
● Knative Eventing Infrastructure -
Kafka Source is autoscaled by KEDA
Consumes
messages
Knative
Eventing
Kafka Source
Knative
Service
Application
Sends
CloudEvents
Monitors load
&
scales
Knative
Service
Application
Knative
Service
Application
Scrapes
metrics
Knative
Eventing
Kafka Source
Knative
Eventing
Kafka Source
Scales
Use Case #4
Redesigned to utilize Knative and KEDA
#Demo
26
knative-sandbox/eventing-autoscaler-keda
metadata:
annotations:
autoscaling.knative.dev/class: keda.autoscaling.knative.dev
autoscaling.knative.dev/minScale: "0"
autoscaling.knative.dev/maxScale: "5"
keda.autoscaling.knative.dev/pollingInterval: "30"
keda.autoscaling.knative.dev/cooldownPeriod: "30"
# Kafka Source
keda.autoscaling.knative.dev/kafkaLagThreshold: "10"
# AWS SQS Source
keda.autoscaling.knative.dev/awsSqsQueueLength: "5"
# Redis Stream Source
keda.autoscaling.knative.dev/redisStreamPendingEntriesCount: "5"
● KafkaSource
● AWS SQS Source
● Redis Stream Source
● RabbitMQ Broker
https://github.com/knative-sandbox/eventing-autoscaler-keda
27
Keep Learning!
bit.ly/danielohtv
Takeaways
28
▸ KEDA - Kubernetes event driven autoscaling dead simple
▸ KEDA - pull model vs. Knative - push model
▸ KEDA - Standard Kubernetes resources vs. Knative Service
▸ KEDA can autoscale Knative Eventing Infrastructure
▸ knative-sandbox/eventing-autoscaler-keda
linkedin.com/company/red-hat
youtube.com/user/RedHatVideos
facebook.com/redhatinc
twitter.com/RedHat
29
Red Hat is the world’s leading provider of enterprise
open source software solutions. Award-winning
support, training, and consulting services make
Red Hat a trusted adviser to the Fortune 500.
Thank you

Event-driven autoscaling through KEDA and Knative Integration | DevNation Tech Talk

  • 1.
    Event-driven Autoscaling through KEDAand Knative Integration Daniel Oh Senior Principal Developer Advocate
  • 2.
    2 About Me Daniel Oh ●Senior Principal Technical Marketing Manager at Red Hat ○ Cloud Native Runtimes ○ Serverless and Service Mesh practices ● Ambassador for CNCF and DevOps Institute ● Advisory Board Member of Global Skill Development Council ● Opensource.com Correspondents ● Public Speaker & Developer Advocate ● Published Author ○ Practical Ansible 2 ○ Quarkus for Spring Developers danieloh30 @danieloh30 bit.ly/danielohtv
  • 3.
  • 4.
    4 Autoscaling Architecture onKubernetes w/ External Services
  • 5.
  • 6.
  • 7.
    7 ● Project aimsto make Kubernetes Event Driven Autoscaling dead simple ● Started as a partnership between Red Hat and Microsoft (Feb 2019) ● Donated into CNCF as a Sandbox project (Mar 2020) ● KEDA 2.0 brought major redesign (Nov 2020) ● Promoting to CNCF Incubation project (Aug 2021) ● KEDA 2.6 has been released recently (Feb 2022) ● https://keda.sh
  • 8.
    8 ● Automatically scaleKubernetes Deployments, Jobs & Custom Resources ● Provides 49+ built-in scalers, but users can build own external scalers ○ Kafka, Prometheus, RabbitMQ, AWS services, Azure Services,... ● Scale resources based on events in the target scalers, eg. messages in Kafka topic ● KEDA does not manipulate the data, just scales the workload ● Installation through OLM Operator or Helm https://keda.sh/docs/2.6/scalers/
  • 9.
  • 10.
    10 How does KEDAworks? ● KEDA is built on top of Kubernetes ● Use ScaledObject/ScaledJob to define scaling metadata ● Manages workloads to scale to 0 ● Registers itself as k8s Metric Adapter ● Provides metrics for Horizontal Pod Autoscaler (HPA) to scale on
  • 11.
    11 ScaledObject apiVersion: keda.sh/v1alpha1 kind: ScaledObject metadata: name:example-so spec: scaleTargetRef: name: example-deployment minReplicaCount: 0 maxReplicaCount: 100 triggers: - type: kafka metadata: bootstrapServers: kafka.svc:9092 consumerGroup: my-group topic: test-topic lagThreshold: '5' ● Can target Deployment, StatefulSet or Custom Resource with scale ● Multiple scalers can be defined as triggers for the target workload ● User can specify HPA related settings to tweak the scaling behavior
  • 12.
  • 13.
  • 14.
    14 ● Operates onstandard k8s resources ● Can scale existing deployed apps ● Pull based approach ● Doesn’t manage data delivery ● K8s Horizontal Pod Autoscaler (HPA) ● Focus is on event driven autoscaling ● Operates on Knative Service ● Existing apps must be converted ● Push based approach ● Manages data delivery (Eventing) ● Knative Autoscaler ● Demand-based autoscaling (HTTP)
  • 15.
    15 Use Case #1 Applicationconsuming messages from Kafka topic ● Application is deployed as standard Kubernetes Deployment ● Can be autoscaled only via standard k8s HPA: CPU & Memory ● No event-driven autoscaling Kubernetes Deployment Application Consumes messages
  • 16.
  • 17.
    17 ● Application remainsthe same and is being deployed the same way ● Event-driven autoscaling enabled through KEDA Scales Kubernetes Deployment Application Consumes messages Scrapes metrics Kubernetes Deployment Application Kubernetes Deployment Application Use Case #2 Redesigned to utilize KEDA
  • 18.
  • 19.
    19 ● Application needsto be rewritten from Kafka consumer to CloudEvents consumer ● Application needs to be redeployed as Knative Service ● Needs Knative Eventing Kafka Source ● Event-driven autoscaling enabled through Knative Autoscaler Consumes messages Knative Eventing Kafka Source Knative Service Application Sends CloudEvents Monitors load & scales Knative Service Application Knative Service Application Use Case #3 Redesigned to utilize Knative
  • 20.
  • 21.
  • 22.
  • 23.
    23 ● KEDA canbe used to autoscale Knative Eventing Infrastructure ○ Knative Eventing Sources, Channels ○ Autoscaling allows infrastructure to handle higher loads or save resources (by scaling to 0) when idle ● KEDA could be potentially used to scale Knative Service, in case users don’t want to utilize Knative Eventing for event driven workloads (currently not implemented) KEDA and Knative Integration
  • 24.
    24 ● Application deployedas Knative Service and autoscaled by Knative ● Knative Eventing Infrastructure - Kafka Source is autoscaled by KEDA Consumes messages Knative Eventing Kafka Source Knative Service Application Sends CloudEvents Monitors load & scales Knative Service Application Knative Service Application Scrapes metrics Knative Eventing Kafka Source Knative Eventing Kafka Source Scales Use Case #4 Redesigned to utilize Knative and KEDA
  • 25.
  • 26.
    26 knative-sandbox/eventing-autoscaler-keda metadata: annotations: autoscaling.knative.dev/class: keda.autoscaling.knative.dev autoscaling.knative.dev/minScale: "0" autoscaling.knative.dev/maxScale:"5" keda.autoscaling.knative.dev/pollingInterval: "30" keda.autoscaling.knative.dev/cooldownPeriod: "30" # Kafka Source keda.autoscaling.knative.dev/kafkaLagThreshold: "10" # AWS SQS Source keda.autoscaling.knative.dev/awsSqsQueueLength: "5" # Redis Stream Source keda.autoscaling.knative.dev/redisStreamPendingEntriesCount: "5" ● KafkaSource ● AWS SQS Source ● Redis Stream Source ● RabbitMQ Broker https://github.com/knative-sandbox/eventing-autoscaler-keda
  • 27.
  • 28.
    Takeaways 28 ▸ KEDA -Kubernetes event driven autoscaling dead simple ▸ KEDA - pull model vs. Knative - push model ▸ KEDA - Standard Kubernetes resources vs. Knative Service ▸ KEDA can autoscale Knative Eventing Infrastructure ▸ knative-sandbox/eventing-autoscaler-keda
  • 29.
    linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHat 29 Red Hat isthe world’s leading provider of enterprise open source software solutions. Award-winning support, training, and consulting services make Red Hat a trusted adviser to the Fortune 500. Thank you