This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.11.5. Using sink binding
Sink binding is used to connect event producers, or event sources, to an event consumer, or event sink, for example, a Knative service or application.
Before developers can use sink binding, cluster administrators must label the namespace that will be configured in the SinkBinding object with bindings.knative.dev/include:"true":
oc label namespace <namespace> bindings.knative.dev/include=true
$ oc label namespace <namespace> bindings.knative.dev/include=true
11.5.1. Using sink binding with the Knative CLI 复制链接链接已复制到粘贴板!
This guide describes the steps required to create, manage, and delete a sink binding instance using the kn CLI.
Prerequisites
- You have Knative Serving and Eventing installed.
-
You have the the
knCLI installed.
The following procedure requires you to create YAML files.
If you change the names of the YAML files from those used in the examples, you must ensure that you also update the corresponding CLI commands.
Before developers can use sink binding, cluster administrators must label the namespace that will be configured in the SinkBinding object with bindings.knative.dev/include:"true":
oc label namespace <namespace> bindings.knative.dev/include=true
$ oc label namespace <namespace> bindings.knative.dev/include=true
Procedure
To check that sink binding is set up correctly, create a Knative event display service, or event sink, that dumps incoming messages to its log:
kn service create event-display --image quay.io/openshift-knative/knative-eventing-sources-event-display:latest
$ kn service create event-display --image quay.io/openshift-knative/knative-eventing-sources-event-display:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
SinkBindingobject that directs events to the service:kn source binding create bind-heartbeat --subject Job:batch/v1:app=heartbeat-cron --sink ksvc:event-display
$ kn source binding create bind-heartbeat --subject Job:batch/v1:app=heartbeat-cron --sink ksvc:event-displayCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a CronJob.
Create a file named
heartbeats-cronjob.yamland copy the following sample code into it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要To use sink binding, you must manually add a
bindings.knative.dev/include=truelabel to your Knative resources.For example, to add this label to a
CronJobobject, add the following lines to the Job resource YAML definition:jobTemplate: metadata: labels: app: heartbeat-cron bindings.knative.dev/include: "true"jobTemplate: metadata: labels: app: heartbeat-cron bindings.knative.dev/include: "true"Copy to Clipboard Copied! Toggle word wrap Toggle overflow After you have created the
heartbeats-cronjob.yamlfile, apply it:oc apply --filename heartbeats-cronjob.yaml
$ oc apply --filename heartbeats-cronjob.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Check that the controller is mapped correctly by entering the following command and inspecting the output:
kn source binding describe bind-heartbeat
$ kn source binding describe bind-heartbeatCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
You can verify that the Kubernetes events were sent to the Knative event sink by looking at the message dumper function logs.
View the message dumper function logs:
oc get pods
$ oc get podsCopy to Clipboard Copied! Toggle word wrap Toggle overflow oc logs $(oc get pod -o name | grep event-display) -c user-container
$ oc logs $(oc get pod -o name | grep event-display) -c user-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.5.2. Using sink binding with the YAML method 复制链接链接已复制到粘贴板!
This guide describes the steps required to create, manage, and delete a sink binding instance using YAML files.
Prerequisites
- You have Knative Serving and Eventing installed.
The following procedure requires you to create YAML files.
If you change the names of the YAML files from those used in the examples, you must ensure that you also update the corresponding CLI commands.
Before developers can use sink binding, cluster administrators must label the namespace that will be configured in the SinkBinding object with bindings.knative.dev/include:"true":
oc label namespace <namespace> bindings.knative.dev/include=true
$ oc label namespace <namespace> bindings.knative.dev/include=true
Procedure
To check that sink binding is set up correctly, create a Knative event display service, or event sink, that dumps incoming messages to its log.
Copy the following sample YAML into a file named
service.yaml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow After you have created the
service.yamlfile, apply it:oc apply -f service.yaml
$ oc apply -f service.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a
SinkBindingobject that directs events to the service.Create a file named
sinkbinding.yamland copy the following sample code into it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- In this example, any Job with the label
app: heartbeat-cronwill be bound to the event sink.
After you have created the
sinkbinding.yamlfile, apply it:oc apply -f sinkbinding.yaml
$ oc apply -f sinkbinding.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a
CronJobobject.Create a file named
heartbeats-cronjob.yamland copy the following sample code into it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要To use sink binding, you must manually add a
bindings.knative.dev/include=truelabel to your Knative resources.For example, to add this label to a cron job instance, add the following lines to the
Jobresource YAML definition:jobTemplate: metadata: labels: app: heartbeat-cron bindings.knative.dev/include: "true"jobTemplate: metadata: labels: app: heartbeat-cron bindings.knative.dev/include: "true"Copy to Clipboard Copied! Toggle word wrap Toggle overflow After you have created the
heartbeats-cronjob.yamlfile, apply it:oc apply -f heartbeats-cronjob.yaml
$ oc apply -f heartbeats-cronjob.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Check that the controller is mapped correctly by entering the following command and inspecting the output:
oc get sinkbindings.sources.knative.dev bind-heartbeat -oyaml
$ oc get sinkbindings.sources.knative.dev bind-heartbeat -oyamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
You can verify that the Kubernetes events were sent to the Knative event sink by looking at the message dumper function logs.
View the message dumper function logs:
oc get pods
$ oc get podsCopy to Clipboard Copied! Toggle word wrap Toggle overflow oc logs $(oc get pod -o name | grep event-display) -c user-container
$ oc logs $(oc get pod -o name | grep event-display) -c user-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow