Introduction to Knative
Knative is a newly announced framework from the folks at Google and Pivotal (and other companies like Red Hat and IBM played minor roles) focused on “serverless” style event driven functions. Let’s have a look at what Knative is.
The Knative framework is built on top of Kubernetes and Istio which provide a an Application runtime (container based) and advanced network routing respectively. This follows the Unix philosophy of “do one thing, and do it well” and allows Knative to focus on its core components of Build, Serving, and Eventing while using Custom Resource Definitions (CRD) to extend the Kubernetes functionality.
For a more detailed look at Developing Servierless Applications on Kubernetes with knative my Pivotal colleagues Brian McClain and Bryan Friedman will be doing a webinar on the topic on the 21st Feb 2019.
Build provides a pluggable model for building your applications [into containers] from source code. It’s based on the Google container building service but can be extended to build containers a number of ways using Build Templates.
Since Knative provides CRDs for its components you can request a build quite simply by creating a Kubernetes manifest that specifies the build template to use along with the source location:
- name: IMAGE
The example above demonstrates using the Kaniko build template which can build Docker images without needing Docker installed or special privileges to build an application from github and then push the resulting image to a Docker registry.
Serving extends Kubernetes to provide for deploying and running serverless workloads. It provides a scale-to-zero compute runtime driven by requests and uses Istio to provide routing to the workload.
Serving will scale the workload based on load. If requests come in when your application is scaled to Zero it will hold those requests while it scales your application back up and then pass the request on. This can cause some significant response time which makes it somewhat unsuitable for general web application usage, but is perfect for batch or event drive jobs (which is exactly it’s purpose!).
The above example is a simple Kubernetes manifest for creating a basic scale-to-zero instance of a container along with the appropriate istio routing.
Eventing provides a way to consume and produce [CloudEvent specification based] events. It can receive events from pluggable event sources and provides delivery through various pub/sub style broker services.
Much of the Eventing components have been taken from Pivotal’s Riff project and Riff now provides an easy to use frontend to Knative.
The above example creates a feed from Kubernetes events and passes them to the application being run by Serving called
read-k8s-events for processing.
Try it out
If you don’t have access to a Kubernetes cluster (or don’t want to take it for a spin yourself) you can watch the following video in which I deploy an application using Knative.