By Peng Li (Yuanyi)
Knative is a serverless framework that is built on Kubernetes. Its main objective is to create a cloud-native and cross-platform orchestration standard for serverless containers. This serverless standard is implemented by Knative through the integration of container building (or function), workload management (dynamic scaling), and event driving.
To provide Knative with production-level event-driven capability, one can leverage the use of the event bus EventBridge. EventBridge is a serverless event bus service offered by Alibaba Cloud. It supports Alibaba Cloud services, custom applications, and software-as-a-service (SaaS) applications in a standard and centralized manner. Furthermore, EventBridge can route events between these services and applications using the standard CloudEvents 1.0 specification. Developers can build loosely coupled and distributed event-driven architectures using EventBridge.
This article describes how to use EventBridge's event to trigger a Knative service, using the example event of uploading files to Object Storage Service (OSS).
EventBridge supports multiple data sources. You can trigger Knative services by configuring event buses, event rules, and event targets to filter and transform events. By utilizing EventBridge's event-driven capability to consume events, you can use resources on demand. The following architecture diagram illustrates the process:
• You have activated EventBridge and granted permissions to a RAM user.
• You have activated the Object Storage Service (OSS). Click here to learn more about the events supported by OSS.
• You have deployed Knative.
In this section, we will use an example Knative Service called "event-display," which directly prints the content of the received event.
1. Create a service.yaml file.
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_3874dbd
2. Run the following command to create a Knative Service:
kubectl apply -f service.yaml
3. Verify the service
$ kubectl get ksvc
NAME URL LATESTCREATED LATESTREADY READY REASON
event-display http://event-display.default.example.com event-display-00009 event-display-00009 True
1. Log on to the EventBridge console. In the left-side navigation pane, choose Integration Center > API Endpoint.
2. In the top navigation bar, select the region where you want to configure the connection. Then, click the Connection Configuration tab.
3. On the Connection Configuration tab, click Create. In the Create Connection panel, configure the following parameters and click OK.
1. After the connection configuration is created, click the API Endpoint tab and click Create.
2. In the Create API Endpoint panel, configure the following parameters and click OK.
a) In the Event Rules tab, configure Name and Description and click Next Step.
b) Configure the event mode and select an official Alibaba Cloud event source.
Event source: acs.oss
a) Configure the event target, and set the following parameters.
Service Type: Select Triggered by API Operation.
Header: The key is the fixed value Host, and the value is the domain name of the Knative service (event-dispaly.default.example.com
).
data
and the value to $.data
. For more information, see https://www.alibabacloud.com/help/en/doc-detail/181428.html for detailsUpload files through OSS to trigger events. Here we upload a demo.data file.
ossutil cp demo.data oss://knative
Log on to the EventBridge console. On the Event Tracking page, you can view the event trace. The event is delivered.
View the Knative service in kubectl. You can see that the automatic trigger creates a new pod.
$ kubectl get po
NAME READY STATUS RESTARTS AGE
event-display-00009-deployment-56cc79666d-z2vhv 2/2 Running 0 7s
The event content has been printed.
$ kubectl logs event-display-00009-deployment-56cc79666d-z2vhv user-container
{"data":{"eventVersion":"1.0","responseElements":{"requestId":"63E21F5FEE852133319101AD"},"eventSource":"acs:oss","eventTime":"2023-02-07T09:52:31.000Z","requestParameters":{"sourceIPAddress":"106.11.167.116"},"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"}}}}
We can see that EventBridge can be seamlessly integrated with Knative, making it easy for Knative to trigger automatic scaling based on events. We expect to further integrate with EventBridge to lower the threshold for configuration.
Practices for Building GitOps Delivery Based on ACK One and ACR
Migrating Applications from the Application Center to ACK One GitOps
167 posts | 30 followers
FollowAlibaba Cloud Native - December 14, 2021
Alibaba Cloud New Products - December 4, 2020
Alibaba Cloud Native - June 12, 2024
Alibaba Developer - April 19, 2022
Alibaba Container Service - September 19, 2024
Alibaba Developer - April 26, 2022
167 posts | 30 followers
FollowAccelerate and secure the development, deployment, and management of containerized applications cost-effectively.
Learn MoreAlibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn MoreAlibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.
Learn MoreEventBridge is a serverless event bus service that connects to Alibaba Cloud services, custom applications, and SaaS applications as a centralized hub.
Learn MoreMore Posts by Alibaba Container Service