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.12+

kubectl version

  • OpenShift CLI should be v4.1+

oc version

The output should be like

oc version
Client Version: version.Info{Major:"4", Minor:"1+", GitVersion:"v4.1.0+b4261e0", GitCommit:"b4261e07ed", GitTreeState:"clean", BuildDate:"2019-07-06T03:16:01Z", GoVersion:"go1.12.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.6+73b5d76", GitCommit:"73b5d76", GitTreeState:"clean", BuildDate:"2019-09-23T16:18:51Z", GoVersion:"go1.12.8", Compiler:"gc", Platform:"linux/amd64"}
  • 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

Watching Logs

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

The logs could be watched using the command:

  • kubectl

  • oc

kubectl logs -n knativetutorial -f <pod-name> -c user-container
oc 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 }