第 12 章 在 Service Mesh 中使用 ContainerSource
您可以在 Service Mesh 中使用容器源。
12.1. 使用 Service Mesh 配置 ContainerSource
此流程描述了如何使用 Service Mesh 配置容器源。
先决条件
- 您已设置了 Service Mesh 和 Serverless 的集成。
流程
在作为
Service
MeshMemberRollevent-display-service.yaml
配置文件示例apiVersion: serving.knative.dev/v1 kind: Service metadata: name: event-display namespace: <namespace> 1 spec: template: metadata: annotations: sidecar.istio.io/inject: "true" 2 sidecar.istio.io/rewriteAppHTTPProbers: "true" spec: containers: - image: quay.io/openshift-knative/knative-eventing-sources-event-display:latest
应用
Service
资源:$ oc apply -f event-display-service.yaml
在作为
ServiceMeshMemberRoll
成员的命名空间中创建ContainerSource
对象,将 sink 设置为event-display
:test-heartbeats-containersource.yaml
配置文件示例apiVersion: sources.knative.dev/v1 kind: ContainerSource metadata: name: test-heartbeats namespace: <namespace> 1 spec: template: metadata: 2 annotations: sidecar.istio.io/inject": "true" sidecar.istio.io/rewriteAppHTTPProbers: "true" spec: containers: # This corresponds to a heartbeats image URI that you have built and published - image: quay.io/openshift-knative/heartbeats name: heartbeats args: - --period=1s env: - name: POD_NAME value: "example-pod" - name: POD_NAMESPACE value: "event-test" sink: ref: apiVersion: serving.knative.dev/v1 kind: Service name: event-display-service
应用
ContainerSource
资源:$ oc apply -f test-heartbeats-containersource.yaml
可选:查看消息转储程序功能日志来验证事件是否已发送到 Knative 事件 sink:
示例命令
$ oc logs $(oc get pod -o name | grep event-display) -c user-container
输出示例
☁️ cloudevents.Event Validation: valid Context Attributes, specversion: 1.0 type: dev.knative.eventing.samples.heartbeat source: https://knative.dev/eventing-contrib/cmd/heartbeats/#event-test/mypod id: 2b72d7bf-c38f-4a98-a433-608fbcdd2596 time: 2019-10-18T15:23:20.809775386Z contenttype: application/json Extensions, beats: true heart: yes the: 42 Data, { "id": 1, "label": "" }