35
Spring Cloud Function & Project riff Japan Spring User Group 2018-02-06 Toshiaki Maki (@making) / Pivotal

Spring Cloud Function & Project riff #jsug

Embed Size (px)

Citation preview

Page 1: Spring Cloud Function & Project riff #jsug

Spring Cloud Function &Project riff

Japan Spring User Group 2018-02-06Toshiaki Maki (@making) / Pivotal

Page 2: Spring Cloud Function & Project riff #jsug

• Keynote day2• https://www.youtube.com/watch?

v=mlRSp9Z3zwY• Serverless Spring

• https://www.youtube.com/watch?v=mPOl3024R4s

Featured Sessions

Page 3: Spring Cloud Function & Project riff #jsug
Page 4: Spring Cloud Function & Project riff #jsug

CONTAINERSEVENT-DRIVEN

FUNCTIONS

DATA SERVICESMICROSERVICES

Batches

MONOLITHIC APPLICATIONS

Companies have many ways to package and run their workloads in the cloud

Page 5: Spring Cloud Function & Project riff #jsug

Their goal: pick the right runtime for each workload

CONTAINERSEVENT-DRIVEN

FUNCTIONS

DATA SERVICESMICROSERVICES

Batches

MONOLITHIC APPLICATIONS

IaaS

ContainerOrchestrator (CaaS)

ApplicationPlatform(PaaS)

Serverless Functions(FaaS)

Page 6: Spring Cloud Function & Project riff #jsug
Page 7: Spring Cloud Function & Project riff #jsug
Page 8: Spring Cloud Function & Project riff #jsug

Why Serverless?

8

1. Narrowly-scoped units of code, and the simplicity of built-in event

integration, contribute to software development efficiencies.

2. Functions which don't consume resources when idle can provide

significant resource efficiencies.

3. Applying serverless to distributed computing brings operational

efficiencies based on automated event-based scheduling and self-scaling.

Page 9: Spring Cloud Function & Project riff #jsug

Who is offering FaaS?Hosted• AWS Lambda• Azure Functions• Google Cloud FunctionsOn-Prem / OSS• riff (https://github.com/projectriff )• Oracle fn• OpenWhisk • Fission• Kubeless• OpenFaaS

Page 10: Spring Cloud Function & Project riff #jsug

• 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

Spring Cloud Function

Page 11: Spring Cloud Function & Project riff #jsug

Spring Cloud Function

• FaaS Portable • Run in Spring Boot• REST, Tasks, or Streams

https://github.com/spring-cloud/spring-cloud-function

Page 12: Spring Cloud Function & Project riff #jsug

HTTP Message

Functions

Spring Cloud Function Web

Spring Cloud Function Message

Spring Boot

Page 13: Spring Cloud Function & Project riff #jsug

HTTP Message

Functions

Spring Cloud Function Adapter

Faas Provider

Page 14: Spring Cloud Function & Project riff #jsug

HTTP Message

Functions

Spring Cloud Function Adapter

Faas Provider

Currently • AWS lambda • Azure Function • Apache OpenWhisk are supported

Page 15: Spring Cloud Function & Project riff #jsug

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();}

Page 16: Spring Cloud Function & Project riff #jsug

Write a functionpackage functions;import java.util.function.Function;public class Greeter implements Function<String, String> {

public String apply(String name) { return "Hello " + name; }

}

Page 17: Spring Cloud Function & Project riff #jsug

Spring Cloud Function (Web)

<dependency> <groupId>org.springframework.cloud<groupId> <artifactId>spring-cloud-function-web</artifactId> <version>1.0.0.M3</version></dependency>

Page 18: Spring Cloud Function & Project riff #jsug

Spring Cloud Function (Message)

<dependency> <groupId>org.springframework.cloud<groupId> <artifactId>spring-cloud-function-message</artifactId> <version>1.0.0.M3</version></dependency>

Page 19: Spring Cloud Function & Project riff #jsug

Spring Cloud Function@SpringBootApplicationpublic class App { @Bean public Greeter greeter() { return new Greeter(); } public static void main(String[] args) { SpringApplication.run(App.class, args); }}

Page 20: Spring Cloud Function & Project riff #jsug

Spring Cloud Function

@SpringBootApplication@FunctionScanpublic class App { public static void main(String[] args) { SpringApplication.run(App.class, args); }}

Page 21: Spring Cloud Function & Project riff #jsug

Spring Cloud Function (Web)

$ curl localhost:8080/greeter \ -w '\n' \ -H "Content-Type: text/plain" \ -d "JSUG"

Hello JSUG

Page 22: Spring Cloud Function & Project riff #jsug

DEMOhttps://github.com/making/demo-function

Page 23: Spring Cloud Function & Project riff #jsug

Project riffhttps://projectriff.io/

Page 24: Spring Cloud Function & Project riff #jsug

riff is for functions

Page 25: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/

what is riff?

24

riff provides developers with a service for executing Functions in response to Events.Features★ event streaming★ polyglot★ Kubernetes-native

Eventsf(x)

f(x)

f(x)

Functionsf(x)

riff

Page 26: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25

🚧

ImmediateInstant-on

ConsistentImmutableContainers

EfficientScale to Zero

Choice of Compromises:

• Launch Function containers on demand => Slow start

• Inject Function code into running containers=> Breaks container immutability

• Keep Function containers running => Pay for idle resources

ICEWant serverless?... pick 2

Page 27: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/

functions are packaged as containers

26

Function Invoker

Function Code

Container Base Image

Function Layer

Container Registry

Page 28: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/

functions are packaged as containers

26

Function Invoker

Function Code

Container Base Image

Function Layer

Container Registry

Currently • Java • JavaScript • Bash • Python are supported

Page 29: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/

sidecars connect functions with event brokers

27

Function Pod

Function ContainerSidecar Container

EventBroker

broker-specific API

binder dispatcher invoker function

HTTP gRPC stdio pipes

Page 30: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/

sidecars connect functions with event brokers

27

Function Pod

Function ContainerSidecar Container

EventBroker

broker-specific API

binder dispatcher invoker function

HTTP gRPC stdio pipes

+ maybe rsocket?

Page 31: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 28

functions and topics are Kubernetes resources

Function Controller

Function YAML - name - input / output topics - artifact / params

Topic YAML - name - params

KafkaHttp Gateway

Topic Controller

Sc Fn

Pod

Sc Fn

Pod

Sc Fn

Pod

k8s API

Page 32: Spring Cloud Function & Project riff #jsug

Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/

functions scale with eventsriff function controller★ interacts with K8s API ★ scales functions 0-1 and 1-N★ monitors event-lag in Kafka

29

Function Controller

Event Broker

f(x)f(x)

f(x)

k8s API

Page 33: Spring Cloud Function & Project riff #jsug

kubectl -n kube-system create serviceaccount tiller kubectl create clusterrolebinding tiller \ --clusterrole cluster-admin \ --serviceaccount=kube-system:tiller helm init --service-account=tiller helm repo add riffrepo https://riff-charts.storage.googleapis.com helm repo update

Set up helm

Installing riff via helm

Page 34: Spring Cloud Function & Project riff #jsug

helm install riffrepo/riff --name demo \ --version 0.0.3-rbac \ --set httpGateway.service.type=NodePort

Installing riff via helmSet up riff

Page 35: Spring Cloud Function & Project riff #jsug

DEMOhttps://github.com/making/demo-riff