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

Learn 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:

    The following example displays event-display-service.yaml configuration 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 the ServiceMeshMemberRoll.
    • sidecar.istio.io/inject: "true": This annotation injects Service Mesh sidecars into the Knative service pods.
  2. Apply the Service object by running the following command:

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

    The following example displays heartbeat-sinkbinding.yaml configuration 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 the ServiceMeshMemberRoll.
    • kind: Job: Bind any Job with the label app: heartbeat-cron to the event sink.
  4. Apply the SinkBinding object by running the following command:

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

    The following example displays heartbeat-cronjob.yaml configuration 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 the ServiceMeshMemberRoll.
    • sidecar.istio.io/inject: "true": Inject Service Mesh sidecars into the CronJob pods.
  6. Apply the CronJob object by running the following command:

    $ oc apply -f heartbeat-cronjob.yaml
  7. Optional: 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-container

    You 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": ""
      }
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top