ContainerSource

ContainerSource will start a container image which will generate events under certain situations and send messages to a sink URI. It also can be an easy way to support your own event sources in Knative. This guide shows how to configure ContainerSource as an event source for functions and summarizes guidelines for creating your own event source as a ContainerSource.

  • Install ko
  • Set (e.g. gcr.io/[gcloud-project] or docker.io/<username>)
  • Authenticated with your KO_DOCKER_REPO
  • Install

The ContainerSource source type is enabled by default when you install Knative Eventing.

This example shows how the heartbeats container sends events to the Event Display Service.

Preparing the heartbeats image

And then build a heartbeats image and publish to your image repo with

  1. ko publish knative.dev/eventing-contrib/cmd/heartbeats

Create a new namespace called containersource-example by entering the following command:

Creating the Event Display Service

In order to verify ContainerSource is working, we will create a Event Display Service that dumps incoming messages to its log.

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: event-display
  5. spec:
  6. replicas: 1
  7. selector:
  8. app: event-display
  9. template:
  10. metadata:
  11. labels: *labels
  12. spec:
  13. containers:
  14. - name: event-display
  15. image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
  16. ---
  17. kind: Service
  18. apiVersion: v1
  19. metadata:
  20. name: event-display
  21. selector:
  22. app: event-display
  23. ports:
  24. - protocol: TCP
  25. port: 80
  26. targetPort: 8080
  27. EOF

Verify

View the logs for the event-display event consumer by entering the following command:

  1. kubectl -n containersource-example logs -l app=event-display --tail=200

This returns the Attributes and Data of the events that the ContainerSource sent to the event-display Service:

Delete the containersource-example namespace and all of its resources from your cluster by entering the following command:

  1. kubectl delete namespace containersource-example

For any inquiries about this source, please reach out on to the .