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

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

Knative event-sources has a sample of heartbeats event source. You could clone the source code by

    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. kubectl -n containersource-example apply -f - << EOF
    2. apiVersion: apps/v1
    3. kind: Deployment
    4. metadata:
    5. name: event-display
    6. spec:
    7. replicas: 1
    8. selector:
    9. app: event-display
    10. template:
    11. metadata:
    12. labels: *labels
    13. spec:
    14. containers:
    15. - name: 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

    In order to run the heartbeats container as an event source, you have to create a concrete ContainerSource with specific arguments and environment settings. Be sure to replace heartbeats_image_uri with a valid uri for your heartbeats image you published in the previous step. Note that arguments and environment variables are set and will be passed to the container.

    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

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

      See the .

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

      Was this page helpful?

      Sorry to hear that. Please .