Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t

3.365 Aufrufe

Veröffentlicht am

Serverless with Spring Cloud Function, Knative and riff

SpringOne Tour Tokyo

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t

  1. 1. !1 Serverless with Spring Cloud Function, Knative and riff 2018-11-06 Toshiaki Maki (@making / tmaki@pivotal.io) SpringOne Tour #s1t
  2. 2. Who am I ? 2 Toshiaki Maki (@making) https://blog.ik.am Advisory Solutions Architect @Pivotal Japan Spring / Cloud Foundry / Concourse / Kubernetes / BOSH
  3. 3. Agenda !3 • Serverless? • Spring Cloud Function • Knative and riff
  4. 4. Agenda !4 • Serverless? • Spring Cloud Function • Knative and riff
  5. 5. Serverless?? !5 • Dynamic resource utilization, "scale to N" and "scale to zero" • Easy integration with platform services • Billing per message • Focus on business logic
  6. 6. Serverless?? !6 • Dynamic resource utilization, "scale to N" and "scale to zero" • Easy integration with platform services • Billing per message • Focus on business logic Knative an riff Spring Cloud Function
  7. 7. Cloud Abstraction !7
  8. 8. Cloud Abstraction !8
  9. 9. Serverless? FaaS? !9 Serverless FaaS λ
  10. 10. Agenda !10 • Serverless? • Spring Cloud Function • Knative and riff
  11. 11. Spring Cloud Function !11 • Focus on the implementation of business logic via functions • Decouple the business logic from any specific runtime (HTTP, Message) • Support a uniform programming model across FaaS providers • Run standalone (locally or in a PaaS) • Enable Spring Boot features on FaaS providers
  12. 12. Spring Cloud Function !12 HTTP Message Spring Boot Spring Cloud Function Web Spring Cloud Stream λ λ λ λ λ
  13. 13. !13 Java Util Function public interface Function<T, R> { R apply(T t); } public interface Consumer<T> { void accept(T t); } public interface Supplier<T> { T get(); }
  14. 14. !14 Write a function package functions; import java.util.function.Function; public class Hello implements Function<String, String> { public String apply(String s) { return "Hello " + s + "!"; } }
  15. 15. Invoke a function via HTTP !15 λ HTTP
  16. 16. Spring Cloud Function !16 HTTP Message Spring Boot Spring Cloud Function Web Spring Cloud Stream λ λ λ λ λ
  17. 17. !17 Spring Cloud Function (Web) <dependency> <groupId>org.springframework.cloud<groupId> <artifactId>spring-cloud-starter-function-web</artifactId> </dependency>
  18. 18. !18 Spring Cloud Function @SpringBootApplication public class App { @Bean public Hello hello() { return new Hello(); } public static void main(String[] args) { SpringApplication.run(App.class, args); } }
  19. 19. !19 Spring Cloud Function @SpringBootApplication public class App { @Bean public Function<String, String> hello() { return name -> "Hello " + s + "!"; } public static void main(String[] args) { SpringApplication.run(App.class, args); } }
  20. 20. !20 Spring Cloud Function (Web) $ curl localhost:8080/hello -w 'n' -H "Content-Type: text/plain" -d "Spring" Hello Spring!
  21. 21. DEMO https://github.com/making/hello-function
  22. 22. !22 λ Message Invoke a function via Messaging
  23. 23. Spring Cloud Function !23 HTTP Message Spring Boot Spring Cloud Function Web Spring Cloud Stream λ λ λ λ λ
  24. 24. !24 Spring Cloud Stream + Function <dependency> <groupId>org.springframework.cloud<groupId> <artifactId>spring-cloud-function-context</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud<groupId> <artifactId>spring-cloud-stream-binder-rabbit</artifactId> </dependency>
  25. 25. !25 Spring Cloud Function Spring Cloud Stream j.u.f.Supplier Source j.u.f.Function Processor j.u.f.Consumer Sink j.u.f = java.util.functions
  26. 26. !26 Spring Cloud Function + Stream @SpringBootApplication @EnableBinding(Processor.class) public class App { @Bean public Function<String, String> hello() { return name -> "Hello " + s + "!"; } public static void main(String[] args) { SpringApplication.run(App.class, args); } }
  27. 27. !27 Spring Cloud Function + Stream spring.cloud.stream.bindings.input.destination=demo-in spring.cloud.stream.bindings.input.group=hello spring.cloud.stream.bindings.output.destination=demo-out spring.cloud.stream.function.definition=hello
  28. 28. DEMO https://github.com/making/hello-function/tree/rabbit
  29. 29. !29 demo-out demo-in.hello λ Exchange Exchange Queue demo-in Provisioned by Spring Cloud Stream
  30. 30. !30 demo-out demo-in.hello λ print Exchange Exchange Queue Queue demo-in
  31. 31. !31 demo-out demo-in.hello λ print Exchange Exchange Queue Queue demo-in λ
  32. 32. !32 demo-out demo-in.hello λ print Exchange Exchange Queue Queue demo-in λ spring.cloud.stream.function.definition=hello|uppercase hello uppercase
  33. 33. Serverless Platform Adapters !33 HTTP Message Spring Cloud Function Adapter Faas Provider λ λ λ λ λ
  34. 34. Serverless Platform Adapters !34 HTTP Message Spring Cloud Function Adapter Faas Provider λ λ λ λ λ Amazon AWS Lambda Apache OpenWhisk Azure Functions Project Riff
  35. 35. !35 <dependency> <groupId>org.springframework.cloud<groupId> <artifactId>spring-cloud-function-adapter-azure</artifactId> </dependency> Example: Azure Functions
  36. 36. Example: Azure Functions !36 import com.microsoft.azure.functions.*; import com.microsoft.azure.functions.annotations.*; import org.springframework.cloud.function.adapter.azure.*; public class AzureHandler extends AzureSpringBootRequestHandler<String, String> { @FunctionName("hello") public String execute(@HttpTrigger(name="req",method=...)) { return super.handleRequest(s, ctx); } }
  37. 37. DEMO https://github.com/making/hello-function/tree/azure
  38. 38. Agenda !38 • Serverless? • Spring Cloud Function • Knative and riff
  39. 39. Serverless? FaaS? !39 Serverless FaaS λ
  40. 40. Serverless? FaaS? !40 Serverless FaaS λ
  41. 41. Knative !41 Knative (pronounced kay-nay-tiv) extends Kubernetes to provide a set of middleware components that are essential to build modern, source-centric, and container-based applications that can run anywhere: on premises, in the cloud, or even in a third-party data center. (from https://github.com/knative/docs)
  42. 42. Overview of Knative !42 Kubernetes-based platform to build, deploy,
 and manage modern serverless workloads Three core components: • Serving - Request-driven compute that can scale to zero • Build - Source-to-container build orchestration • Eventing - Management and delivery of events 100% open source. Created by Google with contributions from Pivotal and others
  43. 43. Knative Custom Resource Definitions !43 BuildTemplate Source Channel Build Flow manages refers to refers to creates and registers instance of Eventing Serving Build
  44. 44. Knative Custom Resource Definitions !44 BuildTemplate Source Channel Build Flow manages refers to refers to creates and registers instance of Eventing Serving Build
  45. 45. Run app/function on Knative Serving !45 apiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: hello namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: making/hello-function
  46. 46. Run app/function on Knative Serving !46 apiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: hello namespace: default spec: runLatest: configuration: revisionTemplate: spec: container: image: making/hello-function http://hello.default.<your-domain>
  47. 47. !47 $ curl ${INGRESS_IP} -w 'n' -H "Host: hello.default.<your-domain>" -H "Content-Type: text/plain" -d "Knative" Hello Knative!
  48. 48. Knative Custom Resource Definitions !48 BuildTemplate Source Channel Build Flow manages refers to refers to creates and registers instance of Eventing Serving Build
  49. 49. Source to URL !49 apiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: hello namespace: default spec: runLatest: configuration: build: source: git: {"url": "https://github.com/making/hello-function.git"} template name: my-build-template arguments: {"name":"IMAGE", "value":"making/hello-function"} configuration: # .. same as previous example
  50. 50. BuildTemplate !50 apiVersion: serving.knative.dev/v1alpha1 kind: BuildTemplate metadata: name: my-build-template namespace: default spec: parameters: - {"name":"IMAGE", "description":"The name of the image to push"} - ... steps: - name: step1 image: foobar/an-image-for-build1 args: ["..."] - name: step2 image: foobar/an-image-for-build2 args: ["..."] https://github.com/knative/build-templates
  51. 51. BuildTemplate !51 apiVersion: serving.knative.dev/v1alpha1 kind: BuildTemplate metadata: name: my-build-template namespace: default spec: parameters: - {"name":"IMAGE", "description":"The name of the image to push"} - ... steps: - name: step1 image: foobar/an-image-for-build1 args: ["..."] - name: step2 image: foobar/an-image-for-build2 args: ["..."] • Kaniko • Jib • Bazel • Buildpack • and so on https://github.com/knative/build-templates
  52. 52. So complex !? !52
  53. 53. Overview of riff !53 riff provides developers with a service for executing functions in response to events. Features: ! Kubernetes-native -> now built on Knative ! polyglot ○ available: Java, node.js, shell commands ○ coming soon: python, ruby, go ! event streaming https://projectriff.io/
  54. 54. riff on Knative !54 Community-driven ecosystem of Sources, Channels, Functions, Invokers, 
 BuildTemplates, etc. Kubernetes BuildTemplates Channels CLI Invokers CLI Invokers Build Topics
  55. 55. riff on Knative !55 Community-driven ecosystem of Sources, Channels, Functions, Invokers, 
 BuildTemplates, etc. Kubernetes BuildTemplates Channels CLI Invokers CLI Invokers Build Topics As of 2018
  56. 56. Function packaging with riff !56 functions are packaged as containers ! Developers are responsible only for the business logic. ! Dependencies in base image layers can be managed independently. ○ simpler ○ more secure ○ more efficient
  57. 57. !57 #!/bin/sh xargs echo -n hello hello.sh module.exports = (x) => x ** 2 square.js Developers write functions
  58. 58. !58 package functions; import java.util.function.Function; public class Hello implements Function<String, String> { public String apply(String s) { return "Hello " + s + "!"; } } Developers write functions
  59. 59. Source to URL !59 $ riff function create java hello --git-repo https://github.com/making/hello-function.git --image making/hello-function --verbose
  60. 60. !60 $ riff service invoke hello --text -- -d Riff -w 'n' Hello Riff!
  61. 61. DEMO https://github.com/making/hello-function
  62. 62. Deploy a Plain Old Function !62 $ riff function create java fizzbuzz --git-repo https://github.com/making/fizz-buzz.git --git-revision develop --image making/fizzbuzz --verbose
  63. 63. !63 $ riff service invoke fizzbuzz --text -- -d 100 -w 'n' Buzz!
  64. 64. Deploy a Knative Service !64 $ riff service create hello --image making/hello-function
  65. 65. !65 $ riff service invoke hello --text -- -d Riff -w 'n' Hello Riff!
  66. 66. Cloud Abstraction !66
  67. 67. Pivotal Function Service (PFS) !67 https://pivotal.io/platform/pivotal-function-service Coming Soon!
  68. 68. Riff / Knative hands-on workshop will be open soon! !68 https://pivotal-japan.connpass.com/
  69. 69. Wrap up: Serverless?? !69 • Dynamic resource utilization, "scale to N" and "scale to zero" • Easy integration with platform services • Billing per message • Focus on business logic
  70. 70. Wrap up: Serverless?? !70 • Dynamic resource utilization, "scale to N" and "scale to zero" • Easy integration with platform services • Billing per message • Focus on business logic Knative an riff Spring Cloud Function
  71. 71. Thanks for your attention! !71 https://projectriff.io/

×