Slide 1

Slide 1 text

Building event-driven systems on Kubernetes — Ian Partridge

Slide 2

Slide 2 text

Ian Partridge • Senior engineer in IBM Hybrid Cloud • Background • Runtime systems development • Open source software • Cloud & Kubernetes Twitter: @alfa GitHub: @ianpartridge 2

Slide 3

Slide 3 text

Agenda • Event-driven systems • Kubernetes & Apache Kafka • KEDA • Demo • Debezium • Knative • Demo 3

Slide 4

Slide 4 text

© 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

Slide 5

Slide 5 text

5 https://www.reactivemanifesto.org Responsive Resilient Elastic Event Driven

Slide 6

Slide 6 text

6 Responsive Microservices

Slide 7

Slide 7 text

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/" }

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Multiple Clients 13 REST based Microservices Event based Microservices µS µS µS REST REST BOTH clients must poll for data changes

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Resilience to Edge Networks 18 REST based Microservices Event based Microservices µS µS REST Network availability determines request success

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Stream Processing 20 REST based Microservices Event based Microservices µS µS REST ML

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

µ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

Slide 23

Slide 23 text

23 Event Driven Ecosystem

Slide 24

Slide 24 text

24 Knative ▪ MySQL ▪ MongoDB ▪ PostgreSQL ▪ Oracle ▪ SQL Server ▪ Db2 ▪ Cassandra

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

•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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

© 2020 IBM Corporation Resilient

Slide 30

Slide 30 text

© 2020 IBM Corporation Resilient

Slide 31

Slide 31 text

© 2020 IBM Corporation Resilient

Slide 32

Slide 32 text

© 2020 IBM Corporation Resilient KAFKA CLIENTS

Slide 33

Slide 33 text

© 2020 IBM Corporation Resilient Topic A Partition 1 Broker 1

Slide 34

Slide 34 text

© 2020 IBM Corporation Resilient Topic A Partition 1 Broker 1 Topic A Partition 1 Offline Leader KAFKA CLIENTS

Slide 35

Slide 35 text

© 2020 IBM Corporation Scalability in Kafka

Slide 36

Slide 36 text

36 Kubernetes Event-driven Autoscaling (KEDA) Serverless for Event Driven Apps Scales on “lag” or “queue depth” Scales to zero when idle KEDA

Slide 37

Slide 37 text

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)

Slide 38

Slide 38 text

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)

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

40 Demo…

Slide 41

Slide 41 text

41 Change Data Capture (CDC) Create events on data change Event enable existing data Modernization of monolithic data stores Debezium

Slide 42

Slide 42 text

: Change Data Capture (CDC) 42

Slide 43

Slide 43 text

43

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

46 Demo…

Slide 47

Slide 47 text

Blockchain Scenario 47 event-source Broker Trigger event-display

Slide 48

Slide 48 text

Blockchain Scenario 48 event-source Broker Trigger event-display Trigger classified- display Trigger classifier

Slide 49

Slide 49 text

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