
Knative Eventing is a standalone platform that is part of the Knative framework used to simplify the deployment and management of serverless applications on Kubernetes Clusters. It offers a set of tools for routing events that allow developers to create and deploy event-driven serverless applications on Kubernetes.
Knative Eventing offers the following components that work together to enable the development of event-driven systems:
In this article, install Knative Eventing and implement the following event patterns on a Vultr Kubernetes Engine (VKE) cluster:
Before you begin:
Knative Serving is a dependency resource required to run Knative Eventing. Install the necessary Knative Service components on your VKE cluster as described in the steps below.
v1.11.0, apply the latest version components to your cluster.Install the Knative Custom Resource Definitions (CRDs)
Install the Knative core components
Install the Knative Kourier controller
Configure Knative Serving to use Kourier as the default controller
Verify that the Kourier controller is available in your cluster
Output:
Verify that the Kourier load balancer resource has a new external IP address
Verify that all Knative Serving components are ready and running
Output:
v1.11.0 is applied in this article, use the latest version to correctly install all components to your cluster.Install the Knative Eventing CRDs
Install the latest Knative Eventing core components
Verify that the installed Knative Eventing components are available and running in your cluster
Output:
Install the in-memory channel to pass events
Install the broker to use available channels and run event routing
Verify if the channel and broker are correctly installed and running
Output:
Knative CLI is a terminal-based tool that allows you to create resources such as Knative services and event sources without creating manifest files. This allows you to scale Knative services up and down based on your requirements within the Kubernetes cluster. Follow the steps below to install Knative CLI on your management server.
Download the latest Knative CLI realease file for Linux systems
When using a different operating system, visit the Knative CLI release page to download the latest build for your OS flavor.
Move the downloaded binary file to the /usr/local/bin/ directory to enable the kn system-wide command
Grant execute permissions on the kn binary file
Verify the installed Knative CLI version
Output:
In Knative eventing, source to sink is a basic pattern that represents the flow of events. Sources are the primary event producers that send events to a sink. A sink is a target of events generated by the source. It's responsible for receiving and responding to incoming events from other resources.
Knative eventing offers many types of event sources. In this section, use the PingSource to produce events with a fixed payload on a specified Cron schedule.
Using the Knative CLI, create a Knative Sink service application named knative-test
Output:
Create a PingSource to continuously send a JSON message Test Message! after every 1 minute to the Knative Service sink knative-test
Verify that the PingSource is available
Output:
View the cluster pods and verify that knative-test is available
Output:
View the logs of any running pod
Your output should look like the one below:
As displayed in the above output, the JSON message sent by PingSource includes the message Test Message you created earlier
Channel and Subscription patterns route events between channels using subscriptions. In Knative, the default In-memory Channel channel provides an interface between the event source and the subscriber. It stores the incoming event data and distributes it to the subscribers.
A Subscription connects a Channel to the event sink (Service) and specifies how events from a channel get delivered to one or more target services. In this section, set up a sample Channel and Subscription pattern using the Knative CLI tool.
Create a new channel named knative-test-channel
Verify that the channel is available
Output:
Using a text editor such as Nano, create a new PingSource sink service file
Add the following configurations to the file
Save and close the file
The above configuration defines a new PingSource resource that can receive and process the events from the Channel
Apply the resource to your cluster
Create a new subscription file to connect the service channel to an event sink
Add the following configurations to the file
Save and close the file
Apply the subscription resource to your cluster
Using the Knative CLI, create another sink service knative-test-2 to view how the channel and the subscriptions work
Verify that the sink service is available in your cluster
Output:
As displayed in the above output, knative-test-2 is the new sink service available in your cluster
Create another subscription knative-test-2-subs to subscribe to the knative-test-channel
Verify that the subscription is available and ready to use
Output:
Verify that all Knative service pods in your cluster are running
Output:
View the logs of any pod to verify if the Channel-Subscription mechanism works
When the pod is running correctly, you should receive the Test Message! JSON output as displayed in the following output:
Before applying a Broker and Trigger to your cluster, remove the ping source, channel, and subscription resources to avoid conflicts
Broker and Trigger are event mesh based patterns that collect a pool of events and distribute them to consumers. They offer a custom filtering mechanism to distribute events based on the trigger type.
Create a new broker named knative-test-broker to collect events
View the new broker resource
Output:
Create a Knative Trigger knative-test-trigger that references the broker, sink and defines the condition type testing1 for incoming events
Create another Trigger knative-test-2-trigger with a different condition named testing2
Verify the created Triggers
Output:
The knative-test service handles events with the type testing1, and knative-test-2 handles events with the type testing2
View the broker Kubernetes service URL to verify your broker and triggers
Output:
Run the following command to send greetings with the type testing1
The above command scales up the knative-test service you have defined with the condition type testing1
View the list of running pods and verify that the knative-test service scales up
Output:
Send another greeting with the type testing2 to scale up the knative-test-2 service
The above command should now scale up the knative-test-2 service. You can verify it using the below command.
View the list of running pods and verify that the knative-test-2 service scales up
Output:
The above output confirms that the filtering mechanism of triggers is successful.
You have implemented different patterns using Knative Eventing on a Vultr Kubernetes Engine (VKE) cluster. Implementing Knative Eventing on the Kubernetes cluster allows you to build scalable, and event-driven microservices. For more information to unlock the full potential of your microservices, visit the official Knative Eventing documentation.
0 Comments
Be the first to comment and share your perspective with the community.