Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Developing Serverless Applications on Kubernetes with Knative - OSCON 2019

56 views

Published on

There's too much fragmentation for developers when it comes to deciding the right open source FaaS solution. Bryan Friedman and Brian McClain detail Knative, an open source project from Google, Pivotal, and other industry leaders that provides a set of common tooling on top of Kubernetes to help developers build functions.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Developing Serverless Applications on Kubernetes with Knative - OSCON 2019

  1. 1. © Copyright 2019 Pivotal Software, Inc. All rights Reserved. Developing Serverless Applications on Kubernetes with Knative Brian McClain @BrianMMcClain Bryan Friedman @bryanfriedman
  2. 2. Cover w/ Image Agenda ■ What is Knative? ■ Example Application ○ Walkthrough on Knative ○ Demo ■ Project riff ■ Q+A
  3. 3. Knative: A platform for developers to build and run serverless applications atop Kubernetes
  4. 4. 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
  5. 5. 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 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 Knative Components
  6. 6. https://pivotal.io/ebooks Available Now
  7. 7. The Example Application
  8. 8. Example Application - Earthquake Visualization
  9. 9. PSQL Frontend Earthquake Event Source Earthquake USGS Event Feed Example Application - High-Level Architecture Geocoder Function
  10. 10. PSQL Geocoder FunctionFrontend Earthquake Event Source Earthquake USGS Event Feed Example Application - High-Level Architecture + Flood Source Flood USGS Event Feed Flood Event Source
  11. 11. Event Format { id: 123456 type: "flood", time: "01:30:00-05:00", lat: "41.5061", long: "-81.6995", measure: 3.38, metadata: { station: ... } }
  12. 12. Example Application - Earthquake + Flood Visualization
  13. 13. Walkthrough on Knative
  14. 14. 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, (percentage-based routing), etc.
  15. 15. {app-name}.{namespace}.{custom-domain} Serving - Deployment n-1 n earthquake-demo.default.dev.gswkbook.com docker.io/gswk/earthquake-demo-frontend:flood
  16. 16. © 2019 PIVOTAL SOFTWARE, INC. All Rights Reserved. Confidential & Provided Under NDA —Do Not Distribute. Forwarding this document outside your organization is prohibited. Cloud Native Buildpacks (CNB) Bring Developer Productivity to K8s Pluggable, modular tools that translate source code into OCI images. ● Portability via the OCI standard ● Greater modularity ● Faster builds ● Run in local dev environments for faster troubleshooting ● Developed in partnership between Pivotal and Heroku ● CNCF project
  17. 17. Pivotal Build Service System Build and package code on-cluster. ● Builds are run completely within Kubernetes ● Code is pulled from git at build time ● Uses Cloud Native Buildpacks ● Packaged as container images; pushed to a registry of your choice ● Underlying CRDs for Build Service to be open source soon!
  18. 18. Build Code Container Image docker.io/gswk/earthquake-demo-frontend:flood https://github.com/gswk/earthquake-demo-frontend.git Build Service System
  19. 19. Demo
  20. 20. 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 ● Brokers provide a place to send events, Triggers direct them where to go ● Pluggable, Customizable Event Sources
  21. 21. 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
  22. 22. 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
  23. 23. Eventing - Direct Delivery Event Source POST / http://geocoder.default.dev.gswkbook.com { id: 123456 type: "flood", time: "01:30:00- 05:00", lat: "41.5061", long: "-81.6995", measure: 3.38, metadata: { station: ... }
  24. 24. Eventing - Broker/Trigger Event Source App Trigger Broker Filter
  25. 25. Eventing - Broker/Trigger Event Source App Trigger Broker Filter Trigger Filter App
  26. 26. Eventing - Broker/Trigger Event Source App Trigger Broker Filter Trigger Filter App
  27. 27. Demo
  28. 28. Example Application - Architecture Geocoder Function Code Frontend Code HTTP 1 2 3 4 Frontend Geocoder Function USGS Earthquake Event Feed PSQL Earthquake Event Source
  29. 29. Example Application - Architecture with New Event Source Geocoder Function Code Frontend Code HTTP 1 2 3 4 Frontend Geocoder Function USGS Earthquake Event Feed PSQL Earthquake Event Source Flood Event Source USGS Flood Event Feed Frontend
  30. 30. Project riff
  31. 31. Project riff Integrated Build Service. Bundled with Pivotal’s Build Service to quickly and securely build container images from source. riff CLI. Make it easy to quickly deploy to Knative. 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
  32. 32. 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); });
  33. 33. Project riff - With Invokers module.exports = x => "Hello, " + x + "!";
  34. 34. Project riff - Deploying Functions
  35. 35. https://pivotal.io/ebooks Available Now @BrianMMcClain @bryanfriedman
  36. 36. github.com/gswk/earthquake-demo
  37. 37. Questions? Q+A
  38. 38. Transforming How The World Builds Software © Copyright 2019 Pivotal Software, Inc. All rights Reserved.

×