how to build a distributed serverless polyglot microservices iot platform using docker and openwhisk

67
Animesh Singh STSM IBM Cloud Platform Cloud Expo, Santa Clara, November 2016 @AnimeshSingh How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Upload: animesh-singh

Post on 15-Apr-2017

2.723 views

Category:

Software


0 download

TRANSCRIPT

Page 1: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Animesh Singh STSM IBM Cloud Platform Cloud Expo, Santa Clara, November 2016 @AnimeshSingh

How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Page 2: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Cloud Computing Evolution

Bare Metal

IaaS

Container Orchestrators PaaS

Page 3: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Problem: It’s expensive to scale microservices, even on a PaaS

Explosion in number of containers / processes:

1.  Increase of infrastructure cost footprint

2.  Increase of operational management cost and complexity

Region B Region A

Break-down into microservices

Make each micro service HA

Protect against regional outages

Monolithic application

Page 4: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Problem: the programming and cost model doesn’t help

•  Continuous polling needed in the absence of an event driven programming model.

•  Charged for resources, even when idle.

•  Worries persist about capacity management.

Swift

Application

Container VM CF

2

Polling

1b

Request

1a

Page 5: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Bare Metal

IaaS

Container Orchestrators PaaS

Enter Serverless!

Serverless

Page 6: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

a cloud-native platform for

short-running, stateless computation and

event-driven applications which

scales up and down instantly and automatically and

charges for actual usage at a millisecond granularity

event handlers events

What is Serverless?

Page 7: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Why is Serverless attractive?

7

Short answer: Besides a)  making app development & ops dramatically faster, cheaper, easier (but different J ), it b)  Drives infrastructure cost savings

(yes – this has been true for most IT innovations over the last decades, while serverless potentially introduces another step-function change)

Page 8: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Key factors for infrastructure cost savings Traditional models (CF, containers, VMs)

Serverless

High Availability At least 2-3 instances of everything

No incremental infrastructure

Multi-region deployment One deployment per region No incremental infrastructure

Cover delta between short (<10s) load spikes and valleys (vs average)

~2x of average load No incremental infrastructure

Example incremental costs 2 instances x 2 regions x 2 = 8x

1x

8

Page 9: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

What is Serverless good for?

9

Page 10: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Introducing OpenWhisk, a fabric and platform for the serverless, event driven programming model

Page 11: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

What is OpenWhisk? an open Beta offering in IBM’s Bluemix cloud

Page 12: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

What is OpenWhisk? an open-source project on github

Page 13: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Build your apps, your way. Use a combination of the most prominent open-source compute

technologies to power your apps. Then, let Bluemix handle the rest.

Ease of getting started Full stack Control

Functions PaaS Containers IaaS

What is OpenWhisk? another way to build apps….

Page 14: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

What is OpenWhisk? a distributed compute service to execute application logic in response "to events.

Page 15: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

OpenWhisk: How does it work?

Incoming HTTP request, e.g. HTTP GET openwhisk.ng.bluemix.net/api/v1/<namespace>/actions/getCustomers

1 Browser

Mobile App

Web App

OpenWhisk

2 Invoke associated OpenWhisk action

„getCustomers“

Swift! Docker JS! Python! Java*!

Variety of languages

* work in progress

Page 16: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

OpenWhisk: How does it work?

-  API Gateway takes care of… -  security (authenticate, authorize, threat protect, validate)

-  control (rate limiting, response caching)

-  mediation

-  parameter mapping

-  schema validation

-  … and supports e.g. different verbs (Get, Post, Put, Delete, …)

Incoming HTTP request, e.g. HTTP GET api-gw.mybluemix.net/…/getCustomers

1 Browser

Mobile App

Web App

AP

I Gat

eway

2

OpenWhisk

3 Invoke associated OpenWhisk action

„getCustomers“

Swift! Docker JS! Python! Java*!

* work in progress

Coming soon...

Page 17: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

The OpenWhisk programming model

Page 18: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

What is OpenWhisk? a high-level serverless programming model

Trigger Rule

Action

Package

Page 19: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

What is OpenWhisk? a high-level serverless programming model

Trigger Rule

Action

Package

language support to encapsulate, share, extend code

first-class event-driven programming constructs

first-class functions compose via sequences

docker containers as actions

all constructs first-class — powerful extensible language

Page 20: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Trigger: A class of events that can happen T

Programming model

Page 21: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Actions: An event-handler, i.e. code that runs in response to an event

A

Programming model

Page 22: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Programming model Actions: Multi-runtime support, e.g. JavaScript A

functionmain(msg){return{message:'Hello,'+msg.name+'from'+msg.place};

};

Page 23: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Actions: Multi-runtime support, e.g. Swift A funcmain(params:[String:Any])->[String:Any]{

varreply=[String:Any]()ifletname=params[“name”]as?String{ print(“Hello\(name)”) reply[“msg”]=“Goodbye\(name)”}returnreply

}

Programming model

Page 24: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Actions: In any other language by packaging with Docker A Programming model

Page 25: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Rules: An association of a trigger and an action R

R := T A

Programming model

Page 26: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Actions: Can be chained to create sequences to increase flexibility and foster reuse A

AA := A1 + A2 + A3

AB := A2 + A1 + A3

AC := A3 + A1 + A2

Programming model

Page 27: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Packages: A shared collection of triggers and actions P

A

A read

write T changes A translate A forecast

A post T topic

Open Source A myAction

T myFeed

Yours

T commit

Third Party

Programming model

Page 28: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

OpenWhisk backend architecture

Page 29: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

github.com

openwhisk/openwhisk

!!!!

coreruntime

CLIpackagessecurityfeatures

persistent store

loggingmonitoring billing

authentication

OpenWhisk on Bluemix

Page 30: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Edge!VM!Edge!

VM!

! Edge!

!!!!

Edge!VM!Edge!

VM!

Master!!!!!!!!!

controllerEdge!VM!Edge!

VM!

!Slave!

!!!!!!!!!!

invoker

•  microservices deployed in docker containers!•  open-source system middleware!•  NoSQL (CouchDB) persistence!

action container!action

container!action container!action

container!action container!action

container!action container!action container

OpenWhisk Open Source Core Runtime

Page 31: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Why Docker?

Page 32: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

controller

invoker

Deploying and managing traditional microservices

1

Why Docker?

Page 33: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Slave VM

Lightweight isolated execution environment for arbitrary user code

action container action container

action container action container

action container action container

action container action container

2

Why Docker?

Page 34: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Portable description of arbitrary binary user actions (Dockerfile)

Docker file

3 Why Docker?

Page 35: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

% wsk action invoke hello in 8 easy steps

How it all works?

POST /api/v1/namespaces/myNamespace/actions/myAction

Page 36: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

36

Controller

… Invoker Invoker Invoker

1!

2!3,4!

5!

6!

7!

8!

OpenWhisk Topology

Page 37: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Cloudant

ELK-Stack

Controller

Integration Service

… Invoker Invoker Invoker

Monitoring

OpenWhisk Topology in Bluemix

Page 38: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

OpenWhisk: Usage of Docker

•  Isolation of actions • Control over consumed resources of each container

38

A = wsk action invoke docker run

Page 39: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

OpenWhisk: Container startup

39

Start container docker run

Initialize /init

Run /run

cold container

Page 40: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Start container docker run

Initialize /init

Run /run

OpenWhisk: Container startup

40

pre-warmed container

Page 41: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Start container docker run

Initialize /init

Run /run

OpenWhisk: Container startup

41

warm container

Page 42: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

OpenWhisk: Container startup optimization

• Performance is king.

42

cold container pre-warmed container warm container

faster

Page 43: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

IoT Usecase Node-RED and MQTT

Page 44: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
Page 45: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
Page 46: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
Page 47: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

CLIENTS BROKER

Page 48: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh SUBSCRIBE

PUBLISH

{…}

{…}

{…}

{…}

Page 49: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

COMMERCIAL OPEN-SOURCE MOSQUITTO

MOSCA

ACTIVEMQ

RABBITMQ

MESSAGESIGHT

HIVEMQ

THINGMQ

CLOUDMQTT

MQTT Brokers

Page 50: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

MQTT NODES IN NODE-RED

Page 51: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

DEVICES NODE-RED

BROKER

Page 52: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh DEVICES

NODE-RED

BROKER

Page 53: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

OpenWhisk Feeds and creating MQTT feeds

Page 54: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Trigger

Action

Action

Action

push, fork, comment, ..

CUSTOM FEED EXAMPLE

Page 55: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

anybody can create a Package with a feed

/whisk.system/github /mynamespace/github

Page 56: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

MQTT feeds for OpenWhisk

•  Bridging MQTT messages to OpenWhisk Actions can be achieved by creating a new Feed provider. This provider would subscribe to message topics and execute registered Triggers with incoming messages.

•  The custom feed provider would need to establish and maintain long-lived MQTT connections, waiting for messages to arrive. This requirements means the Feed provider needs an external service to handle managing these connections, it won’t be possible within the Feed Action.

•  This feed provider service is implemented using Node.js, using Cloudant for the database. The service listens for HTTP requests, with Trigger registration details, from the Feed Action. The Node.js MQTT library is used to subscribe to registered topics. When messages are received, the OpenWhisk client library is used to invoke the Trigger remotely, passing the message contents as event parameters.

•  This service provider is packaged using Docker. Pushing this image into the IBM Containers registry, the Feed provider can be started on IBM Bluemix using the Containers service.

http://jamesthom.as/blog/2016/06/15/openwhisk-and-mqtt/

Page 57: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

MQTT feeds for OpenWhisk •  This service provider is packaged using Docker.

•  Pushing this image into the IBM Containers registry, the Feed provider can be started on IBM Bluemix using the Containers service.

Page 58: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Registering Feeds http://jamesthom.as/blog/2016/06/15/openwhisk-and-mqtt/

Page 59: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Node-RED for Serverless OpenWhisk

Page 60: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Node-RED and OpenWhisk •  Community effort to integrate with open tools: NodeRED

•  NodeRED is all about automating flows to orchestrate calls to

different service APIs •  Usually triggered by calls from external systems or devices •  Runs within a long-running single node process, with a dedicated amount of CPU & memory

being allocated

•  OpenWhisk is all about executing code (custom logic) in response to events on a scalable platform, with a dedicated amount of CPU & memory being allocated per-request

•  NodeRED and OpenWhisk complement each other •  Use NodeRED to graphically create flows, automating a series of tasks in a kind of workflow •  Use OpenWhisk to execute custom logic (requiring some kind of CPU- or memory bound

operation) triggered from within NodeRED

Page 61: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

•  Use Node-RED to create Multi cloud Serveless Applications!

Use Node-RED to compose Serverless Applications

$ wsk property set --apihost openwhisk.ng.bluemix.net --auth 96294c7b-e6f4-4ccf --namespace “animeshsingh" $ wsk action invoke /whisk.system/utils/

echo -p message hello --blocking --result

{ "message": "hello" }

Page 62: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Devices Node-RED & OpenWhisk

MQTT Broker Trigger

Action

Action

Action

Bringing it all together – Serverless IoT Applications

Page 63: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Summary

Page 64: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

What you learned today

• We’re in the early days of an evolution that is empowering developers to write cloud native applications better, faster, and cheaper

• OpenWhisk provides an open source platform to enable cloud native, serverless, event driven applications

• OpenWhisk, MQTT and Node-RED can be used together to create IoT Serverless applications

Page 65: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Experiment with OpenWhisk on Bluemix

bit.ly/ow-bm

Page 66: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

@AnimeshSingh

Join us to build a cloud native platform for the future!

OpenWhisk.org dwopen.slack.com #openwhisk bluemix.net

OpenWhisk and MQTT http://jamesthom.as/blog/2016/06/15/openwhisk-and-mqtt/

Page 67: How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

Thank You