Este conteúdo não está disponível no idioma selecionado.
Chapter 16. Using a sink binding with Service Mesh
You can use a sink binding with Service Mesh.
16.1. Configuring a sink binding with Service Mesh Copiar o linkLink copiado para a área de transferência!
Learn how to configure a sink binding with Service Mesh.
Prerequisites
- You have set up integration of Service Mesh and Serverless.
Procedure
Create a
Serviceobject in a namespace that is member of theServiceMeshMemberRoll:The following example displays
event-display-service.yamlconfiguration file:apiVersion: serving.knative.dev/v1 kind: Service metadata: name: event-display namespace: <namespace> spec: template: metadata: annotations: sidecar.istio.io/inject: "true" sidecar.istio.io/rewriteAppHTTPProbers: "true" spec: containers: - image: quay.io/openshift-knative/knative-eventing-sources-event-display:latest-
namespace: <namespace>: a namespace that is a member of theServiceMeshMemberRoll. -
sidecar.istio.io/inject: "true": This annotation injects Service Mesh sidecars into the Knative service pods.
-
Apply the
Serviceobject by running the following command:$ oc apply -f event-display-service.yamlCreate a
SinkBindingobject:The following example displays
heartbeat-sinkbinding.yamlconfiguration file:apiVersion: sources.knative.dev/v1alpha1 kind: SinkBinding metadata: name: bind-heartbeat namespace: <namespace> spec: subject: apiVersion: batch/v1 kind: Job selector: matchLabels: app: heartbeat-cron sink: ref: apiVersion: serving.knative.dev/v1 kind: Service name: event-display-
namespace: <namespace>: A namespace that is part of theServiceMeshMemberRoll. -
kind: Job: Bind any Job with the labelapp: heartbeat-cronto the event sink.
-
Apply the
SinkBindingobject by running the following command:$ oc apply -f heartbeat-sinkbinding.yamlCreate a
CronJobobject:The following example displays
heartbeat-cronjob.yamlconfiguration file:apiVersion: batch/v1 kind: CronJob metadata: name: heartbeat-cron namespace: <namespace> spec: # Run every minute schedule: "* * * * *" jobTemplate: metadata: labels: app: heartbeat-cron bindings.knative.dev/include: "true" spec: template: metadata: annotations: sidecar.istio.io/inject: "true" sidecar.istio.io/rewriteAppHTTPProbers: "true" spec: restartPolicy: Never containers: - name: single-heartbeat image: quay.io/openshift-knative/heartbeats:latest args: - --period=1 env: - name: ONE_SHOT value: "true" - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace-
namespace: <namespace>: A namespace that is part of theServiceMeshMemberRoll. -
sidecar.istio.io/inject: "true": Inject Service Mesh sidecars into theCronJobpods.
-
Apply the
CronJobobject by running the following command:$ oc apply -f heartbeat-cronjob.yamlOptional: Verify that the events reach the Knative event sink by checking the message dumper function logs:
You get an output similar to the following example command:
$ oc logs $(oc get pod -o name | grep event-display) -c user-containerYou get an output similar to the following example:
☁️ 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": "" }