This is a cache of https://docs.openshift.com/serverless/1.33/eventing/sinkbinding-with-ossm.html. It is a snapshot of the page at 2024-11-24T16:43:43.256+0000.
Using a sink binding with OpenShift <strong>service</strong> Mesh | Eventing | Red Hat OpenShift Serverless 1.33
×

You can use a sink binding with service Mesh.

Configuring a sink binding with service Mesh

This procedure describes how to configure a sink binding with service Mesh.

Prerequisites
  • You have set up integration of service Mesh and Serverless.

Procedure
  1. Create a service object in a namespace that is member of the serviceMeshMemberRoll:

    Example event-display-service.yaml configuration file
    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
    1 A namespace that is a member of the serviceMeshMemberRoll.
    2 This annotation injects service Mesh sidecars into the Knative service pods.
  2. Apply the service object:

    $ oc apply -f event-display-service.yaml
  3. Create a SinkBinding object:

    Example heartbeat-sinkbinding.yaml configuration file
    apiVersion: sources.knative.dev/v1alpha1
    kind: SinkBinding
    metadata:
      name: bind-heartbeat
      namespace: <namespace> (1)
    spec:
      subject:
        apiVersion: batch/v1
        kind: Job (2)
        selector:
          matchLabels:
            app: heartbeat-cron
    
      sink:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: service
          name: event-display
    1 A namespace that is part of the serviceMeshMemberRoll.
    2 Bind any Job with the label app: heartbeat-cron to the event sink.
  4. Apply the SinkBinding object:

    $ oc apply -f heartbeat-sinkbinding.yaml
  5. Create a CronJob object:

    Example heartbeat-cronjob.yaml configuration file
    apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: heartbeat-cron
      namespace: <namespace> (1)
    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" (2)
                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
    1 A namespace that is part of the serviceMeshMemberRoll.
    2 Inject service Mesh sidecars into the CronJob pods.
  6. Apply the CronJob object:

    $ oc apply -f heartbeat-cronjob.yaml
  7. Optional: Verify that the events were sent to the Knative event sink by looking at the message dumper function logs:

    Example command
    $ oc logs $(oc get pod -o name | grep event-display) -c user-container
    Example output
    ☁️  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": ""
      }