Kubernetes Event-driven
Autoscaling
Adam Hamsik
adam.hamsik@lablabs.io
Labyrinth Labs
Rock-solid infrastructure and DevOps
● Building rock-solid and secure foundations for all your digital operations. Our
mission is to let you focus on your business without ever needing to worry
about technical issues again.
● Making you ready for growing traffic, safe against new security vulnerabilities
and data-loss.
2
TL;DR
● What is event driven architecture and why does it look like serverless ?
● How KEDA works
○ When does it make sense to use it ?
○ What scalers KEDA supports ?
● Do you have any real life example for KEDA and event driven autoscaling ?
3
Event Driven Architecture
● Architecture design where systems/services communicate with
events/messages.
● Event broker/message bus is used/shared for communication between services
● Services can scale based on events not resource load
○ Lambda, knative, functions
● Can process huge number of events very quickly
● Can make sure time ordering of events
4
5
Kubernetes Event-driven Architecture
Simple explanation
● Standard K8s HPA is monitoring particular metrics and scale deployment based
on them.
○ Imagine you are inviting friends to a BD party and you want to order a pizza for snack. In HPA
terms you will order one pizza and when they will be eaten for 60% your order new batch.
● KEDA helps us to change HPA behaviour to Event driven
○ You order new pizza every time new guest comes to a party.
6
Kubernetes Event-driven
Autoscaling
● Open Source project (MIT license)
○ Originally written by Microsoft/Redhat engineers
○ Current version is v2.1.0 released in January 2021
○ Open and built with community
○ Hosted at: https://github.com/kedacore/keda
● Part of CNCF currently in a Sandbox
7
Kubernetes Event-driven
Autoscaling
● Monitors rate of events and to proactively scale application resources /
workload.
● Can upscale/downscale HPA/Deployment from/to zero containers.
○ Deployment can have 0 replicas at beginning (e.g. if there are no messages in a queue)
● Keda gathers info from scalers and feeds it to Kubernetes API
○ This will reuse already existing Metrics server and HPA implementations.
● Support large number of scalers, can be extended
○ AWS SQS, AWS cloudwatch, AWS kinesis, Apache Kafka, RabbitMQ, ActiveMQ, Google Cloud
Platform Pub/Sub, Azure Storage Queue, Azure Service Bus and many more.
8
9
Kubernetes Event-driven Autoscaling
Core Principles
● Works with any Kubernetes cluster
● Can scale any container, deployment or workload.
● Don’t rebuild anything Kubernetes already has
○ HPA, Metrics Server
○ Use existing technologies to extend kubernetes features CRD
10
11
https://keda.sh/img/keda-arch.png
Long running jobs
Problem: If we scale scale our workload for message processing and it takes a
while to finish single message we risk HPA will downscale our pod.
● Generic Kubernetes solution: is to postpone pod termination indefinitely (very
long gracefulTerminationPeriod + lifecycle preStop hook.
● Use KEDA ScaleJob CRD to create k8s jobs per event.
12
Demo time
13
14
● RabbitMQ message consumer
deployment
● Keda ScaleOut object monitoring
number of messages in a given queue
and scaling our deployment.
Real life example for event driven scaling
15/22
● During game events we see huge spike in incoming requests during very short
period of time [~5minutes]
○ If we knew in advance that game events starts at 12:00 can we prepare our
application/infrastructure for it ?
● Sometimes we have to kick players from game and force them to relogin which
is a DB heavy operation
○ We want to do it in batches while monitoring DB load. To make sure that we do not overload it.
● Scale Message queue consumers based on queue messages
Real life example for event driven scaling
16/22
Real life example for event driven scaling
17/22
Questions ?
18
Thank You.
We are hiring, remote working DevOps/Kubernetes
engineers.
adam.hamsik@lablabs.io
www.lablabs.io
19

Cncf event driven autoscaling with keda

  • 1.
  • 2.
    Labyrinth Labs Rock-solid infrastructureand DevOps ● Building rock-solid and secure foundations for all your digital operations. Our mission is to let you focus on your business without ever needing to worry about technical issues again. ● Making you ready for growing traffic, safe against new security vulnerabilities and data-loss. 2
  • 3.
    TL;DR ● What isevent driven architecture and why does it look like serverless ? ● How KEDA works ○ When does it make sense to use it ? ○ What scalers KEDA supports ? ● Do you have any real life example for KEDA and event driven autoscaling ? 3
  • 4.
    Event Driven Architecture ●Architecture design where systems/services communicate with events/messages. ● Event broker/message bus is used/shared for communication between services ● Services can scale based on events not resource load ○ Lambda, knative, functions ● Can process huge number of events very quickly ● Can make sure time ordering of events 4
  • 5.
  • 6.
    Simple explanation ● StandardK8s HPA is monitoring particular metrics and scale deployment based on them. ○ Imagine you are inviting friends to a BD party and you want to order a pizza for snack. In HPA terms you will order one pizza and when they will be eaten for 60% your order new batch. ● KEDA helps us to change HPA behaviour to Event driven ○ You order new pizza every time new guest comes to a party. 6
  • 7.
    Kubernetes Event-driven Autoscaling ● OpenSource project (MIT license) ○ Originally written by Microsoft/Redhat engineers ○ Current version is v2.1.0 released in January 2021 ○ Open and built with community ○ Hosted at: https://github.com/kedacore/keda ● Part of CNCF currently in a Sandbox 7
  • 8.
    Kubernetes Event-driven Autoscaling ● Monitorsrate of events and to proactively scale application resources / workload. ● Can upscale/downscale HPA/Deployment from/to zero containers. ○ Deployment can have 0 replicas at beginning (e.g. if there are no messages in a queue) ● Keda gathers info from scalers and feeds it to Kubernetes API ○ This will reuse already existing Metrics server and HPA implementations. ● Support large number of scalers, can be extended ○ AWS SQS, AWS cloudwatch, AWS kinesis, Apache Kafka, RabbitMQ, ActiveMQ, Google Cloud Platform Pub/Sub, Azure Storage Queue, Azure Service Bus and many more. 8
  • 9.
  • 10.
    Core Principles ● Workswith any Kubernetes cluster ● Can scale any container, deployment or workload. ● Don’t rebuild anything Kubernetes already has ○ HPA, Metrics Server ○ Use existing technologies to extend kubernetes features CRD 10
  • 11.
  • 12.
    Long running jobs Problem:If we scale scale our workload for message processing and it takes a while to finish single message we risk HPA will downscale our pod. ● Generic Kubernetes solution: is to postpone pod termination indefinitely (very long gracefulTerminationPeriod + lifecycle preStop hook. ● Use KEDA ScaleJob CRD to create k8s jobs per event. 12
  • 13.
  • 14.
    14 ● RabbitMQ messageconsumer deployment ● Keda ScaleOut object monitoring number of messages in a given queue and scaling our deployment.
  • 15.
    Real life examplefor event driven scaling 15/22 ● During game events we see huge spike in incoming requests during very short period of time [~5minutes] ○ If we knew in advance that game events starts at 12:00 can we prepare our application/infrastructure for it ? ● Sometimes we have to kick players from game and force them to relogin which is a DB heavy operation ○ We want to do it in batches while monitoring DB load. To make sure that we do not overload it. ● Scale Message queue consumers based on queue messages
  • 16.
    Real life examplefor event driven scaling 16/22
  • 17.
    Real life examplefor event driven scaling 17/22
  • 18.
  • 19.
    Thank You. We arehiring, remote working DevOps/Kubernetes engineers. [email protected] www.lablabs.io 19