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]
ordocker.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.
kubectl -n containersource-example apply -f - << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: event-display
spec:
replicas: 1
selector:
app: event-display
template:
metadata:
labels: *labels
spec:
containers:
- name: event-display
---
kind: Service
apiVersion: v1
metadata:
name: event-display
selector:
app: event-display
ports:
- protocol: TCP
port: 80
targetPort: 8080
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:
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 .