Knative Tutorial

At the end of this chapter you will know and understand:

  • What is an event source?

  • What is a channel?

  • What is a subscriber?

  • What is a trigger?

  • What is a broker?

  • How to make a Knative serving service receive an event?

  • How to make a service a subscriber of an event?

Prerequisite

The following checks ensure that each chapter exercises are done with the right environment settings.

  • Kubernetes

  • OpenShift

  • Set your local docker to use minikube docker daemon

eval $(minikube docker-env)
  • Kubernetes should be v1.16+

kubectl version --short

The output should be as shown

Client Version: v1.18.2
Server Version: v1.18.2
  • OpenShift CLI should be v4.3+

oc version

The output should be like

oc version
Client Version: openshift-clients-4.3.0-201910250623-88-g6a937dfe
Kubernetes Version: v1.16.2
  • Make sure to be on knativetutorial OpenShift project

oc project -q

If you are not on knativetutorial project, then run following command to change to knativetutorial project:

oc project knativetutorial

Before beginning to run the exercises, navigate to the tutorial chapter’s eventing folder:

cd $TUTORIAL_HOME/eventing

Watching Logs

In the eventing related subsections of this tutorial, event sources are configured to emit events every minute with a PingSource or with a ContainerSource.

The logs could be watched using the command:

kubectl logs -n knativetutorial -f <pod-name> -c user-container
  • Using stern with the command stern -n knativetutorial event-greeter, to filter the logs further add -c user-container to the stern command.

stern -n knativetutorial -c user-container event-greeter

The logs will have the output like below printing every minute.

INFO  [com.red.dev.dem.GreetingService] (XNIO-1 task-1) Event Message Received
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container  {
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container   "message" : "Thanks for doing Knative Tutorial",
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container   "host" : "Event  greeter => 'event-greeter-5cbh5-pod-52d8fb' : 1",
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container   "time" : "13:50:07"
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container }

(OR)

INFO  [com.red.dev.dem.GreetingService] (XNIO-1 task-1) Event Message Received
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container  {
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container   "message" : "Thanks for doing Knative Tutorial",
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container   "host" : "Event  greeter => 'event-greeter-5cbh5-pod-52d8fb' : 2",
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container   "time" : "13:51:00"
event-greeter-g94kp-deployment-89f66cb58-wjl2v user-container }