© Copyright 2019 Pivotal Software, Inc. All rights Reserved.
Brian McClain
Bryan Friedman
Developing Serverless Applications
on Kubernetes with Knative
Webinar
Cover w/ Image
Agenda
■ What is Knative?
■ Knative Components with Examples
■ Project riff
■ Demo Application
■ Q+A
Knative: A platform for developers to
build and run serverless applications
atop Kubernetes
Eventing
How your code is
triggered by events
● Apps and functions consume
and publish event streams
● Multiple event sources available
● Encourages asynchronous,
loosely coupled architecture
Build
How your code is built and
packaged as a container
● Pluggable model to build
containers from source code
● Build in-cloud or on-cluster
● Push image to registry
● Templates available
(e.g. Buildpacks)
Serving
How your code receives requests
and scales with them
● Request-driven compute runtime
● Scale-to-zero / scale out per load
● Deploy from container registry
● Multiple revisions of same app
● Route traffic across revisions
DETAILS DETAILS DETAILS
Knative Components
Serving
Flexible scaling and routing to your application.
● Automatically deploy containers and configure routing
● Automatically scale up and down, including scale-to-zero
● Point-in-time snapshots of deployments allows multiple versions of
applications at once
● Easy rollbacks, blue-green deployments, partial load testing, etc.
{app-name}.{namespace}.{custom-domain}
Serving - Deployment
n-1
n
name.default.example.com
Serving - Deployment
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: knative-helloworld
namespace: default
spec:
runLatest:
configuration:
revisionTemplate:
spec:
container:
image: docker.io/gswk/knative-helloworld:latest
n+1
Serving - Request Handling
n-1
n
HTTP
knative-helloworld.default.dev.gswkbook.com
n+1
Serving - Scaling Up
n-1
n n n
HTTP
n+1
Serving - Scaling Down
n-1
n
Serving - Scaling Down
n+1
Serving - Scaling Down
n-1
n
Serving - Percentage-Based Routing
n-1
n
HTTP 100%
name: v1
n+1
Serving - Percentage-Based Routing
n-1
n
HTTP 100%
0%
name: v1
name: v2
n+1
Serving - Percentage-Based Routing
n-1
n
HTTP 50%
50%
name: v2
name: v1
n+1
Serving - Percentage-Based Routing
n-1
n
HTTP 0%
100%
name: v2
name: v1
Serving - Percentage-Based Routing
apiVersion: serving.knative.dev/v1alpha1
kind: Route
metadata:
name: knative-routing-demo
namespace: default
spec:
traffic:
- revisionName: knative-routing-demo-00001
name: v1
percent: 50
- revisionName: knative-routing-demo-00002
name: v2
percent: 50
Build
Build and package code on-cluster.
● Builds are ran completely within Kubernetes
● Code is pulled from git at build time
● Packaged as container images and pushed to a registry of your
choice
● Build Templates are prepackaged descriptions of different ways to
build code
Kaniko. Build container images inside of containers
Jib. Build container images optimized for Java applications
Buildpacks. Build container images using Cloud Foundry’s Buildpack
build system
And more! The list of Build Templates is constantly growing
Build Templates
Build
Code
Container
Image
Build
spec:
runLatest:
configuration:
build:
serviceAccountName: build-bot
source:
git:
url: https://github.com/gswk/knative-build-demo.git
revision: master
template:
name: kaniko
arguments:
- name: IMAGE
value: docker.io/gswk/knative-build-demo:latest
Eventing
Robust eventing support that abstracts away the messaging layer.
● Easy for developers to consume events - No messaging-specific
code
● Messaging layer is abstracted from the developer and pluggable
for the operator
● Abstract persistent Channels allows events to be delivered to
multiple functions
● Pluggable, Customizable Event Sources
Example Event Sources
Cron Job. Produce events on a specified Cron schedule
GitHub. Events happening in a GitHub repository/organization (commit,
new pull request, etc) trigger your function
Google Cloud Storage. Invokes your function when files are uploaded
or changed in a specified bucket
AWS SQS. Messages on SQS are forwarded to your function
Custom Event Sources
Event Sources are pluggable and not tightly bundled to Knative
● Community-developed event sources are installed by applying a
YAML file
● ContainerSource makes it easy to build your own event source
○ Package your event emitter as a container, Knative gives a
URI to POST to
Eventing - Direct Delivery
Event
Source
Eventing - Fan-Out Delivery
Event
Source
Channel
Subscription
Subscription
Eventing - Channel
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
metadata:
name: knative-eventing-demo-channel
spec:
provisioner:
apiVersion: eventing.knative.dev/v1alpha1
kind: ClusterChannelProvisioner
name: in-memory-channel
Eventing - Source
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: KubernetesEventSource
metadata:
name: k8sevents
spec:
namespace: default
serviceAccountName: events-sa
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: knative-eventing-demo-channel
Eventing - Subscription
apiVersion: eventing.knative.dev/v1alpha1
kind: Subscription
metadata:
name: knative-eventing-demo-subscription
spec:
channel:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: knative-eventing-demo-channel
subscriber:
ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: knative-eventing-demo-app
Custom Event Sources - Container Source
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: ContainerSource
metadata:
labels:
controller-tools.k8s.io: "1.0"
name: my-event-source
spec:
image: docker.io/gswk/my-event-source:latest
sink:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: my-event-source
Project riff
Evolution of Project riff
Project riff
Makes Knative Better. Tools and extensions to make the Knative
developer experience even better
riff CLI. Make easy to quickly deploy functions to Knative and configure
event channels. Removes the need to manage YAML.
Invokers. Allows developers to focus on their functions, invokers will
handle setting up the webserver and running your code
Project riff - Without Invokers
const express = require("express");
const bodyParser = require('body-parser')
const app = express();
app.use(bodyParser.text({type: "*/*"}));
app.post("/", function(req, res) {
res.send("Hello, " + req.body + "!");
});
const port = process.env.PORT || 8080;
app.listen(port, function() {
console.log("Server started on port", port);
});
Project riff - With Invokers
module.exports = x => "Hello, " + x + "!";
Project riff - Deploying Functions
Pivotal's commercially supported, opinionated
packaging of riff + Knative.
Expected to run on PKS or Kubernetes anywhere.
Alpha Release Now Available (by request)
General Availability TBD
Demo
Demo Application - Earthquake Visualization
PSQL
Geocoder
Function
Frontend
USGS
Event
Source
USGS
Event
Feed
Demo Application - High-Level Visualization
Demo Application - Detailed Visualization
Geocoder
Function
Code
Frontend
Code
HTTP
1
2
3
4
Frontend
Geocoder
Function
USGS
Event
Feed
PSQL
USGS
Event
Source
https://pivotal.io/ebooks
Available Now
@BrianMMcClain
@bryanfriedman
Join Us At CF
Summit
@BrianMMcClain
@bryanfriedman
Questions?
Q+A
Transforming How The World Builds Software
© Copyright 2019 Pivotal Software, Inc. All rights Reserved.

Developing Serverless Applications on Kubernetes with Knative

  • 1.
    © Copyright 2019Pivotal Software, Inc. All rights Reserved. Brian McClain Bryan Friedman Developing Serverless Applications on Kubernetes with Knative Webinar
  • 3.
    Cover w/ Image Agenda ■What is Knative? ■ Knative Components with Examples ■ Project riff ■ Demo Application ■ Q+A
  • 4.
    Knative: A platformfor developers to build and run serverless applications atop Kubernetes
  • 5.
    Eventing How your codeis triggered by events ● Apps and functions consume and publish event streams ● Multiple event sources available ● Encourages asynchronous, loosely coupled architecture Build How your code is built and packaged as a container ● Pluggable model to build containers from source code ● Build in-cloud or on-cluster ● Push image to registry ● Templates available (e.g. Buildpacks) Serving How your code receives requests and scales with them ● Request-driven compute runtime ● Scale-to-zero / scale out per load ● Deploy from container registry ● Multiple revisions of same app ● Route traffic across revisions DETAILS DETAILS DETAILS Knative Components
  • 6.
    Serving Flexible scaling androuting to your application. ● Automatically deploy containers and configure routing ● Automatically scale up and down, including scale-to-zero ● Point-in-time snapshots of deployments allows multiple versions of applications at once ● Easy rollbacks, blue-green deployments, partial load testing, etc.
  • 7.
  • 8.
    Serving - Deployment apiVersion:serving.knative.dev/v1alpha1 kind: Service metadata: name: knative-helloworld namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: docker.io/gswk/knative-helloworld:latest
  • 9.
    n+1 Serving - RequestHandling n-1 n HTTP knative-helloworld.default.dev.gswkbook.com
  • 10.
    n+1 Serving - ScalingUp n-1 n n n HTTP
  • 11.
  • 12.
  • 13.
  • 14.
    Serving - Percentage-BasedRouting n-1 n HTTP 100% name: v1
  • 15.
    n+1 Serving - Percentage-BasedRouting n-1 n HTTP 100% 0% name: v1 name: v2
  • 16.
    n+1 Serving - Percentage-BasedRouting n-1 n HTTP 50% 50% name: v2 name: v1
  • 17.
    n+1 Serving - Percentage-BasedRouting n-1 n HTTP 0% 100% name: v2 name: v1
  • 18.
    Serving - Percentage-BasedRouting apiVersion: serving.knative.dev/v1alpha1 kind: Route metadata: name: knative-routing-demo namespace: default spec: traffic: - revisionName: knative-routing-demo-00001 name: v1 percent: 50 - revisionName: knative-routing-demo-00002 name: v2 percent: 50
  • 19.
    Build Build and packagecode on-cluster. ● Builds are ran completely within Kubernetes ● Code is pulled from git at build time ● Packaged as container images and pushed to a registry of your choice ● Build Templates are prepackaged descriptions of different ways to build code
  • 20.
    Kaniko. Build containerimages inside of containers Jib. Build container images optimized for Java applications Buildpacks. Build container images using Cloud Foundry’s Buildpack build system And more! The list of Build Templates is constantly growing Build Templates
  • 21.
  • 22.
    Build spec: runLatest: configuration: build: serviceAccountName: build-bot source: git: url: https://github.com/gswk/knative-build-demo.git revision:master template: name: kaniko arguments: - name: IMAGE value: docker.io/gswk/knative-build-demo:latest
  • 23.
    Eventing Robust eventing supportthat abstracts away the messaging layer. ● Easy for developers to consume events - No messaging-specific code ● Messaging layer is abstracted from the developer and pluggable for the operator ● Abstract persistent Channels allows events to be delivered to multiple functions ● Pluggable, Customizable Event Sources
  • 24.
    Example Event Sources CronJob. Produce events on a specified Cron schedule GitHub. Events happening in a GitHub repository/organization (commit, new pull request, etc) trigger your function Google Cloud Storage. Invokes your function when files are uploaded or changed in a specified bucket AWS SQS. Messages on SQS are forwarded to your function
  • 25.
    Custom Event Sources EventSources are pluggable and not tightly bundled to Knative ● Community-developed event sources are installed by applying a YAML file ● ContainerSource makes it easy to build your own event source ○ Package your event emitter as a container, Knative gives a URI to POST to
  • 26.
    Eventing - DirectDelivery Event Source
  • 27.
    Eventing - Fan-OutDelivery Event Source Channel Subscription Subscription
  • 28.
    Eventing - Channel apiVersion:eventing.knative.dev/v1alpha1 kind: Channel metadata: name: knative-eventing-demo-channel spec: provisioner: apiVersion: eventing.knative.dev/v1alpha1 kind: ClusterChannelProvisioner name: in-memory-channel
  • 29.
    Eventing - Source apiVersion:sources.eventing.knative.dev/v1alpha1 kind: KubernetesEventSource metadata: name: k8sevents spec: namespace: default serviceAccountName: events-sa sink: apiVersion: eventing.knative.dev/v1alpha1 kind: Channel name: knative-eventing-demo-channel
  • 30.
    Eventing - Subscription apiVersion:eventing.knative.dev/v1alpha1 kind: Subscription metadata: name: knative-eventing-demo-subscription spec: channel: apiVersion: eventing.knative.dev/v1alpha1 kind: Channel name: knative-eventing-demo-channel subscriber: ref: apiVersion: serving.knative.dev/v1alpha1 kind: Service name: knative-eventing-demo-app
  • 31.
    Custom Event Sources- Container Source apiVersion: sources.eventing.knative.dev/v1alpha1 kind: ContainerSource metadata: labels: controller-tools.k8s.io: "1.0" name: my-event-source spec: image: docker.io/gswk/my-event-source:latest sink: apiVersion: serving.knative.dev/v1alpha1 kind: Service name: my-event-source
  • 32.
  • 33.
  • 34.
    Project riff Makes KnativeBetter. Tools and extensions to make the Knative developer experience even better riff CLI. Make easy to quickly deploy functions to Knative and configure event channels. Removes the need to manage YAML. Invokers. Allows developers to focus on their functions, invokers will handle setting up the webserver and running your code
  • 35.
    Project riff -Without Invokers const express = require("express"); const bodyParser = require('body-parser') const app = express(); app.use(bodyParser.text({type: "*/*"})); app.post("/", function(req, res) { res.send("Hello, " + req.body + "!"); }); const port = process.env.PORT || 8080; app.listen(port, function() { console.log("Server started on port", port); });
  • 36.
    Project riff -With Invokers module.exports = x => "Hello, " + x + "!";
  • 37.
    Project riff -Deploying Functions
  • 38.
    Pivotal's commercially supported,opinionated packaging of riff + Knative. Expected to run on PKS or Kubernetes anywhere. Alpha Release Now Available (by request) General Availability TBD
  • 39.
  • 40.
    Demo Application -Earthquake Visualization
  • 41.
  • 42.
    Demo Application -Detailed Visualization Geocoder Function Code Frontend Code HTTP 1 2 3 4 Frontend Geocoder Function USGS Event Feed PSQL USGS Event Source
  • 43.
  • 44.
    Join Us AtCF Summit @BrianMMcClain @bryanfriedman
  • 45.
  • 46.
    Transforming How TheWorld Builds Software © Copyright 2019 Pivotal Software, Inc. All rights Reserved.