Knative Eventing provides a complete event model for integrating external event sources. Deploy Knative Eventing in your ACK cluster and create triggers to route EventBridge events to Knative Services for event-driven workloads.EventBridge events to Knative Services for event-driven workloads.
Prerequisites
-
Knative Serving version is 1.12.7 or later.
-
Activate EventBridge and grant the required permissions.
NoteSee What is EventBridge?.
How it works
EventBridge receives events from various sources. You configure an event bus, rules, and targets to filter, transform, and route events to Knative Services for on-demand consumption. The following figure shows the architecture.
You can connect OSS to EventBridge as an event source. See OSS events for supported event types.
Step 1: Deploy the Eventing and EventBridge components
Knative uses EventBridge for event-driven capabilities, supporting Alibaba Cloud event sources and event forwarding.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Add-ons tab, deploy the Eventing and EventBridge components.
-
On the Add-ons tab, find the Eventing component and click Deployments in the Actions column.
-
After Eventing is deployed, find the EventBridge component and click Deployments in the Actions column. Enter your AccessKey ID and AccessKey secret, then click OK.
NoteTo enhance the security of your RAM user, you can bind an MFA device for secondary authentication during console sign-ins or when you perform sensitive operations. This provides an extra layer of protection beyond a username and password. For more information, see Bind an MFA device for a RAM user.
If the Status of the components is Deployed, the deployment is successful.
-
Step 2: Create a Knative Service
Create a Knative Service named event-display that logs received events. You can use the ACK console or kubectl.
Console
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Services tab, click Create from Template.
Example:
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: event-display namespace: default spec: template: spec: containers: - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/event-display:20230207194118_3874dbdOn the Services tab, a Status of Success confirms the Service is created.
Kubectl
-
Save the following as
event-display.yamland apply it:apiVersion: serving.knative.dev/v1 kind: Service metadata: name: event-display namespace: default spec: template: spec: containers: - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/event-display:20230207194118_3874dbdkubectl apply -f event-display.yaml -
Check the Knative Service status:
kubectl get ksvcExpected output:
NAME URL LATESTCREATED LATESTREADY READY REASON event-display http://event-display.default.example.com event-display-00001 event-display-00001 True
Step 3: Create a trigger
Console
-
On the Knative page, click the Services tab. Click the target Service, then click the Trigger tab.
-
Click Create Trigger. On the Configuration page, set the following parameters:
Parameter
Description
Example
Name
The trigger name.
my-service-trigger
Broker
Select EventBridge or Others.
EventBridge
Event Source
Select an event source.
OSS
Event Type
Select an event type.
oss:ActionTrail:ConsoleOperation
The trigger appears on the Triggers tab.
Kubectl
-
Save the following as
my-service-trigger.yamland apply it:apiVersion: eventing.knative.dev/v1 kind: Trigger metadata: name: my-service-trigger spec: broker: eventbridge-default-broker filter: attributes: source: acs.oss type: 'oss:ActionTrail:ConsoleOperation' subscriber: ref: apiVersion: serving.knative.dev/v1 kind: Service name: event-display namespace: default-
broker: Theeventbridge-default-broker, corresponding to the default event bus (default) in EventBridge. -
source: The event source. -
type: The event type. Separate multiple types with a comma (,). -
subscriber: The target Knative Service.
kubectl apply -f my-service-trigger.yaml -
-
Check the trigger status:
kubectl get triggersExpected output:
NAME BROKER SUBSCRIBER_URI AGE READY REASON my-service-trigger eventbridge-default-broker http://event-display.default.svc.cluster.local 42h True
Step 4: Verify event consumption
-
Upload a file to your OSS bucket.
NoteThe OSS bucket and EventBridge must be in the same region.
ossutil cp <file_name> oss://<bucket_name>After the upload, EventBridge triggers the Knative Service to consume the event.
-
View the Event Trace.
Log on to the EventBridge console. In the left-side navigation pane, click Event Buses.
-
Find the default event bus and click Event Tracking in the Actions column. On the Query By Time Range tab, set a Time Range and click Search.
-
Find the event where the Event Source is Object Storage Service and the Event Type is Upload Object. Click Event Trace in the Actions column.
A delivery status of Succeeded with response
[200]confirms EventBridge delivered the event.The Event Trace page shows the full delivery status.
-
Verify that the Knative Service consumed the event.
-
Check for the pod created to consume the event:
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE event-display-00001-deployment-56cc79****-z2vhv 2/2 Running 0 7s -
View the logs to confirm the Knative Service recorded the event:
kubectl logs event-display-00001-deployment-56cc79****-z2vhv user-containerExpected output:
{"data":{"eventVersion":"1.0","responseElements":{"requestId":"63E21F5FEE852133319101AD"},"eventSource":"acs:oss","eventTime":"2023-02-07T09:52:31.000Z","requestParameters":{"sourceIPAddress":"XX.XXX.XX.XXX"},"eventName":"ObjectCreated:PutObject","userIdentity":{"principalId":"1118324452360952"},"region":"cn-hangzhou","oss":{"bucket":{"name":"knative","arn":"acs:oss:cn-hangzhou:1581204543170042:knative","virtualBucket":"","ownerIdentity":"1581204543170042"},"ossSchemaVersion":"1.0","object":{"size":225496,"objectMeta":{"mimeType":"application/octet-stream"},"deltaSize":0,"eTag":"B350C082843DAC7E9E634193437EBA30","key":"demo.data"}}}}
The output confirms the Knative Service consumed the OSS file upload event.
-