Mastering Knative Sequence: Build Event‑Driven Pipelines with 4 Real‑World Scenarios
This guide explains how Knative Eventing's Sequence CRD enables multi‑step event pipelines, walks through its spec definition, and demonstrates four practical usage patterns—direct service calls, event‑driven processing, cascading sequences, and Broker/Trigger integration—complete with YAML examples and visual diagrams.
What is Knative Sequence?
When a piece of data must pass through multiple processing stages, developers call it a pipeline. Starting with Knative Eventing 0.7, the Sequence Custom Resource Definition (CRD) provides native support for such pipelines. This article introduces the Sequence definition and four common usage scenarios.
Sequence Specification
apiVersion: messaging.knative.dev/v1alpha1
kind: Sequence
metadata:
name: test
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
steps:
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: test
reply:
kind: Broker
apiVersion: eventing.knative.dev/v1alpha1
name: testThe spec consists of three parts:
steps : defines an ordered list of services; each step creates a Subscription.
channelTemplate : selects the concrete Channel implementation.
reply (optional): specifies where the result of the last step is sent.
Four Practical Scenarios
Direct Service Access
Event‑Driven Processing
Cascading Sequences
Broker/Trigger Integration
1. Direct Service Access
An event source sends events straight to a Sequence, which invokes a chain of Knative Services (first → second → third). The services simply log the received event.
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: first
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/probable-summer:latest
env:
- name: STEP
value: "0"
---
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: second
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/probable-summer:latest
env:
- name: STEP
value: "1"
---
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: third
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/probable-summer:latest
env:
- name: STEP
value: "2" apiVersion: messaging.knative.dev/v1alpha1
kind: Sequence
metadata:
name: sequence
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
steps:
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: first
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: second
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: thirdThe resulting flow is illustrated below:
2. Event‑Driven Processing
A CronJobSource emits a JSON payload every minute, which is routed to the Sequence. After the three services process the event, the final result is sent to an event-display service for visualization.
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: CronJobSource
metadata:
name: cronjob-source
spec:
schedule: "*/1 * * * *"
data: '{"message": "Hello world!"}'
sink:
apiVersion: messaging.knative.dev/v1alpha1
kind: Sequence
name: sequence apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: event-display
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-release/event_display:latest3. Cascading Sequences
Sequences can be chained, allowing one Sequence to feed its output into another. This enables complex multi‑stage pipelines.
apiVersion: messaging.knative.dev/v1alpha1
kind: Sequence
metadata:
name: first-sequence
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
steps:
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: first
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: second
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: third
reply:
kind: Sequence
apiVersion: messaging.knative.dev/v1alpha1
name: second-sequence apiVersion: messaging.knative.dev/v1alpha1
kind: Sequence
metadata:
name: second-sequence
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
steps:
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: fourth
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: fifth
- ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: sixth
reply:
kind: Service
apiVersion: serving.knative.dev/v1alpha1
name: event-display4. Broker/Trigger Integration
A CronJobSource sends events to a default Broker. A Trigger routes those events to a Sequence, and another Trigger forwards the Sequence’s output to the event-display service.
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: CronJobSource
metadata:
name: cronjob-source
spec:
schedule: "*/1 * * * *"
data: '{"message": "Hello world!"}'
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Broker
name: default apiVersion: eventing.knative.dev/v1alpha1
kind: Trigger
metadata:
name: sequence-trigger
spec:
filter:
sourceAndType:
type: dev.knative.cronjob.event
subscriber:
ref:
apiVersion: messaging.knative.dev/v1alpha1
kind: Sequence
name: sequence apiVersion: eventing.knative.dev/v1alpha1
kind: Trigger
metadata:
name: display-trigger
spec:
filter:
sourceAndType:
type: samples.http.mod3
subscriber:
ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: event-displayConclusion
The article introduced the Sequence CRD, explained its spec, and demonstrated four real‑world patterns for building event‑driven pipelines in Knative Eventing. By selecting the appropriate scenario, developers can efficiently orchestrate multi‑step event processing on Kubernetes‑based serverless platforms.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
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.
