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]
ordocker.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
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.
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
image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
---
kind: Service
apiVersion: v1
metadata:
name: event-display
selector:
app: event-display
ports:
- protocol: TCP
port: 80
targetPort: 8080
EOF
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
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:
kubectl delete namespace containersource-example
For any inquiries about this source, please reach out on to the .