Understanding Knative Eventing: Core Concepts, Components, and Workflow Examples
This article explains Knative Eventing’s role in serverless event‑driven architectures, detailing its core concepts, the generic event‑listening model, key components such as Sources, Channels, Subscriptions, Brokers, Triggers, and flow resources like Sequence and Parallel, and provides practical YAML and HTTP examples.
Knative Eventing is a Cloud Native Computing Foundation (CNCF) project that enables server‑less, event‑driven architectures on Kubernetes. It provides a set of APIs that let developers route events from producers (sources) to consumers (sinks) while supporting the CloudEvents specification.
The generic event‑listening model consists of producers and consumers that communicate either by push or polling. Without a standard, this model often leads to tightly coupled logic and poor portability. Knative Eventing abstracts this model with reusable, loosely‑coupled components.
Key components of Knative Eventing include:
Event Source : creates events from external systems (e.g., GitHub, Kubernetes) and forwards them into the mesh.
Channel : a buffered conduit between sources and subscribers; implementations include InMemoryChannel, Apache Kafka, and NATS Streaming.
Subscription : binds a Channel to a consumer (or another Channel) and defines delivery semantics.
Sink : a generic addressable target (Service, Broker, etc.) that receives events via HTTP.
Broker : a higher‑level event router that can filter and fan‑out events to multiple Triggers.
Trigger : defines filter criteria and the final subscriber for events arriving at a Broker.
Knative Eventing adopts the CloudEvents format. Two encoding modes are supported:
POST /event HTTP/1.0
HOST: example.com
Content-type: application/json
ce-specversion: 1.0
ce-type: com.bigco.newItem
ce-source: http://bigco.com/repo
ce-id: A333-111-dfsf-fdsf3-0987
{"action": "newItem", "itemID": "92"}Structured mode (payload wrapped in a CloudEvents‑specific JSON content type):
POST /event HTTP/1.0
HOST: example.com
Content-type: application/cloudevents+json
{"specversion": "1.0", "type": "com.bigco.newItem", "source": "http://bigco.com/repo", "id": "A333-111-dfsf-fdsf3-0987", "datacontenttype": "application/json", "data": {"action": "newItem", "itemID": "92"}}CloudEvents defines required attributes (source, id, specversion, type) and optional ones (datacontenttype, dataschema, subject, time). Extension attributes such as dataref , traceparent , and partitionkey are also supported.
Additional higher‑level flow resources allow composition of multiple components:
Sequence : an ordered list of Services that process an event one after another.
Parallel : a set of Services that receive the same event concurrently, each optionally applying a filter or transformer.
Example YAML definitions illustrate how to create these resources.
# PingSource (event source)
apiVersion: sources.knative.dev/v1
kind: PingSource
metadata:
name: ping-source
namespace: default
spec:
schedule: "*/1 * * * *"
contentType: "application/json"
data: '{"message": "Hello world!"}'
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display # InMemoryChannel (channel)
apiVersion: messaging.knative.dev/v1
kind: Channel
metadata:
name: my-channel-example
namespace: default # Subscription (channel → service)
apiVersion: messaging.knative.dev/v1beta1
kind: Subscription
metadata:
name: subscription1
namespace: default
spec:
channel:
apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel
name: channel1
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-processor
reply:
ref:
apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel
name: channel2 # Broker
apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
name: my-broker
namespace: default # Trigger (filter → service)
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: my-trigger
namespace: default
spec:
broker: my-broker
filter:
attributes:
type: dev.knative.foo.bar
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: my-service # Sequence (ordered services)
apiVersion: flows.knative.dev/v1
kind: Sequence
metadata:
name: my-sequence
namespace: eventing-example
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
steps:
- ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: first
- ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: second
- ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: third
reply:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display # Parallel (concurrent branches)
apiVersion: flows.knative.dev/v1
kind: Parallel
metadata:
name: odd-even-parallel
namespace: eventing-example
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
branches:
- filter:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: even-filter
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: even-transformer
- filter:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: odd-filter
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: odd-transformer
reply:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-displayThese examples demonstrate how Knative Eventing can be assembled to build flexible, scalable, and decoupled event‑driven applications on Kubernetes. By leveraging standard CloudEvents and reusable CRDs, developers gain portability across cloud providers and on‑premise environments.
The article concludes that mastering Knative Eventing’s building blocks—Sources, Channels, Subscriptions, Brokers, Triggers, and flow resources—enables the creation of robust serverless pipelines, and that future posts will dive deeper into specific patterns and best practices.
360 Smart Cloud
Official service account of 360 Smart Cloud, dedicated to building a high-quality, secure, highly available, convenient, and stable one‑stop cloud service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.