Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building event-driven systems on Kubernetes

Building event-driven systems on Kubernetes

Event-driven architectures can offer compelling benefits in comparison to traditional REST-based systems. Key use cases include streaming analytics, edge computing, push-based frontends, and systems where traditional fault tolerance solutions are insufficient. This session gives an introduction to eventing and discusses the pros and cons of event-based architectures. Knative Eventing is a framework to enable development of asynchronous event-driven apps on Kubernetes; we will see the system in action including live demos. Additionally, Kubernetes Event Driven Autoscaling (KEDA) solves a separate but related problem: providing "scale to zero" for event driven workloads. We’ll show KEDA in action scaling an event-driven workload with Apache Kafka and discuss the future of eventing on Kubernetes.

Presented at JAX 2020.

https://jax.de/cloud-container-serverless/building-event-driven-systems-on-kubernetes/

Ian Partridge

September 10, 2020
Tweet

More Decks by Ian Partridge

Other Decks in Programming

Transcript

  1. Ian Partridge • Senior engineer in IBM Hybrid Cloud •

    Background • Runtime systems development • Open source software • Cloud & Kubernetes Twitter: @alfa GitHub: @ianpartridge 2
  2. Agenda • Event-driven systems • Kubernetes & Apache Kafka •

    KEDA • Demo • Debezium • Knative • Demo 3
  3. © 2020 IBM Corporation Users demand responsive, real-time applications Apps

    must react to events in real time, as they happen Apps must deliver responsive customer experiences Apps enhanced with real-time intelligence
  4. REST Microservices • REpresentational State Transfer became the de facto

    way of building microservices • Microservices communicate over HTTP(S) • Client/server model • REST APIs use standard verbs: • GET, POST, PUT, DELETE • JSON became the standard data format • REST APIs are documented using OpenAPI • Standard description format 7 $ http swapi.dev/api/planets/1/ HTTP/1.0 200 OK Content-Type: application/json { "climate": "Arid", "diameter": "10465", "gravity": "1 standard", "name": "Tatooine", "orbital_period": "304", "population": "200000", "residents": [ "https://swapi.dev/api/people/1/", "https://swapi.dev/api/people/2/", ... ], "rotation_period": "23", "surface_water": "1", "terrain": "Dessert", "url": "https://swapi.dev/api/planets/1/" }
  5. Event-driven Architectures • Instead of command/response, focus on events •

    An event is a record of fact • Events can be transmitted via messages • Messages can be stored durably • Push vs pull • Messages can be multiplexed 8
  6. Responsiveness 9 REST based Microservices Event based Microservices µS µS

    REST Client must poll to discover data/state changes
  7. Responsiveness 10 REST based Microservices Event based Microservices µS µS

    REST Client must poll to discover data/state changes Data becomes immediately available to Client µS µS
  8. Long Running Tasks 11 REST based Microservices Event based Microservices

    µS REST Client must poll to discover data/state changes against ID HTTP requests timeout at 100 seconds* “Workaround” to return a request ID
  9. Long Running Tasks 12 REST based Microservices Event based Microservices

    µS REST Client must poll to discover data/state changes against ID Update pushed when long running task completes µS HTTP requests timeout at 100 seconds* “Workaround” to return a request ID
  10. Multiple Clients 13 REST based Microservices Event based Microservices µS

    µS µS REST REST BOTH clients must poll for data changes
  11. Multiple Clients 14 REST based Microservices Event based Microservices µS

    µS µS REST REST OR flow must be in reverse: but.. any outage during calls means a notification is lost
  12. One produced event is consumed by two clients Multiple Clients

    15 REST based Microservices Event based Microservices µS µS µS µS µS µS REST REST OR flow must be in reverse: but.. any outage during calls means a notification is lost
  13. Failure of µService causes failure of request Resilience to failure

    16 REST based Microservices Event based Microservices µS µS REST µS
  14. Failure of µService causes failure of request Resilience to failure

    17 REST based Microservices Event based Microservices µS REST µS µS Event backbone stores state enabling requests to continue after µService restart µS µS
  15. Resilience to Edge Networks 18 REST based Microservices Event based

    Microservices µS µS REST Network availability determines request success
  16. Requests queued until network availability µS µS Resilience to Edge

    Networks 19 REST based Microservices Event based Microservices µS µS REST Network availability determines request success
  17. Stream Processing 21 REST based Microservices Event based Microservices µS

    µS REST ML µService has to be repeatedly called with new data and manage/store history
  18. µService has to be repeatedly called with new data and

    manage/store history Stream Processing 22 REST based Microservices Event based Microservices µS µS REST µS µS µService receives continuous stream of data and has access to history ML ML
  19. 24 Knative ▪ MySQL ▪ MongoDB ▪ PostgreSQL ▪ Oracle

    ▪ SQL Server ▪ Db2 ▪ Cassandra
  20. •Provision, manage & scale containerised applications •Manage infrastructure resources needed

    by applications •Volumes •Networks •Secrets •And much more.. •What's in a name? •Kubernetes (k8s/Kube): "Helmsman" in ancient Greek Container Orchestrator
  21. DB API Server Client/User Watchers Controllers Node Networks Volumes Secrets

    ... Request Monitor • At its core, Kubernetes is: • A distributed database (etcd) • "Watchers" & "controllers" that react to changes in etcd. The controllers are what make it Kubernetes. • DB holds the user's desired state • Watchers & controllers attempt to make reality match the desired state • "API Server" is an HTTP/REST front-end to the DB Architecture
  22. 28 Distributed streaming platform Publish and subscribe to streams of

    records Store records in durable way Process streams of records as they occur Apache Kafka
  23. © 2020 IBM Corporation Resilient Topic A Partition 1 Broker

    1 Topic A Partition 1 Offline Leader KAFKA CLIENTS
  24. 36 Kubernetes Event-driven Autoscaling (KEDA) Serverless for Event Driven Apps

    Scales on “lag” or “queue depth” Scales to zero when idle KEDA
  25. 37 • 2 roles: • Activate/deactivate Deployment for scale to

    zero • Expose event metrics (like queue length) to the HPA • Lightweight (3 CRDs) • KedaController • ScaledObject • TriggerAuthentication • Deploy via operator, Helm or YAML • Lots of scalars • Kafka, AWS SQS, Azure Event Hub, GCP Pub/Sub, Liiklus, NATS, Prometheus, RabbitMQ, Redis Lists Kubernetes Event-driven Autoscaling (KEDA)
  26. 38 • Joint Microsoft / Red Hat project • v1.0

    for KubeCon 2019 ( https://youtu.be/ZK2SS_GXF-g ) • Donated to CNCF for incubation • Headed for OpenShift: • “Our goal is to continue making KEDA a first class citizen in OpenShift, easy to consume and install, so you won’t need to be an expert and can focus on your application, freeing developers from infrastructure concerns. With the work being done to build a Kubernetes Operator for KEDA using the Operator SDK, and the built-in support for Operators in OpenShift 4 we are making the installation and management of KEDA in OpenShift easier.” • https://www.redhat.com/en/blog/celebrating-keda-10-providing-event-driven-scale-capability-any- container-workload Kubernetes Event-driven Autoscaling (KEDA)
  27. 39 Coffeeshop scenario Coffeeshop UI Kafka event bus HTTP Barista

    Kafka Baristas REST over HTTP * Kafka pub/sub occurs using MicroProfile Reactive Messaging Kafka pub/sub Kafka pub/sub https://github.com/ianpartridge/coffeeshop-demo
  28. 41 Change Data Capture (CDC) Create events on data change

    Event enable existing data Modernization of monolithic data stores Debezium
  29. 43

  30. Knative • Knative Serving • Run serverless containers on Kubernetes

    with ease, Knative takes care of the details of networking, autoscaling (even to zero), and revision tracking. • Knative Eventing • Universal subscription, delivery, and management of events. Build modern apps by attaching compute to a data stream with declarative event connectivity and developer- friendly object model. 44
  31. Knative Eventing • Knative Eventing services are loosely coupled •

    Events can be transient or durable • Integrates with Knative Services and k8s Services • Key terminology • Broker - mediates events, forwarding and persisting as appropriate • Trigger - filter on events • Service - receive events 45
  32. 49 • Event-driven architectures can deliver the responsive, resilient and

    elastic characteristics modern applications require • An emerging cloud-native stack of Kubernetes, Kafka, Knative and KEDA has the capabilities needed for building internet-scale event-driven applications • Thank you! Summary