Be a Microservices Hero | ContainerCon15 Dragos Dascalita Haut | - - PowerPoint PPT Presentation

be a microservices hero containercon 15
SMART_READER_LITE
LIVE PREVIEW

Be a Microservices Hero | ContainerCon15 Dragos Dascalita Haut | - - PowerPoint PPT Presentation

h tu ps://github.com/adobe-apiplatform Be a Microservices Hero | ContainerCon15 Dragos Dascalita Haut | Adobe Presentation scripts: h tu ps://gist.github.com/ddragosd/608bf8d3d13e3f688874 A CreativeCloud Microservice Sample: Content-Aware fj ll


slide-1
SLIDE 1

Be a Microservices Hero | ContainerCon’15

Dragos Dascalita Haut | Adobe

htups://github.com/adobe-apiplatform

Presentation scripts: htups://gist.github.com/ddragosd/608bf8d3d13e3f688874

slide-2
SLIDE 2
slide-3
SLIDE 3

A CreativeCloud Microservice Sample: Content-Aware fjll

slide-4
SLIDE 4

A CreativeCloud Microservice Sample: send to Photoshop from the mobile device

slide-5
SLIDE 5

Lifecycle of a microservice

slide-6
SLIDE 6

Growing the microservices ecosystem

slide-7
SLIDE 7

API Platform

slide-8
SLIDE 8

API Platform

slide-9
SLIDE 9

api1 api2

slide-10
SLIDE 10
slide-11
SLIDE 11

How to make it easier to scale Microservices in this model ?

slide-12
SLIDE 12

Microservices Microservices , , Containers Containers & Apache & Apache Mesos Mesos write containerize & deploy write containerize & deploy write containerize & deploy

slide-13
SLIDE 13

Apache Apache Mesos Mesos

slide-14
SLIDE 14

Apache Apache Mesos Mesos & & Microservices Microservices

“Program for the data center “Program for the data center Just like you program for the OS” Just like you program for the OS” Computer: Computer: Kernel: Kernel: OS: OS: Services: Services: Tra Traffi ffic Ctrl: c Ctrl: Data Center Data Center Mesos Mesos Mesos Mesos Frameworks, Marathon, Frameworks, Marathon, Mesosphere’s DCOS Mesosphere’s DCOS Microservices Microservices API Gateway API Gateway

  • Facilitates inter-API communication

Facilitates inter-API communication

  • Routing, Tra

Routing, Traffi ffic Shaping, Filtering c Shaping, Filtering

slide-15
SLIDE 15

Apache Apache Mesos Mesos & & Microservices Microservices

SETUP A MINI-DATA-CENTER SETUP A MINI-DATA-CENTER 4 VMs , 1 Leader, 2 Slaves, 1 Admin 4 VMs , 1 Leader, 2 Slaves, 1 Admin

#DEMO #DEMO

slide-16
SLIDE 16

Simple ways to get started: Simple ways to get started:

  • htu

tups://mesosphere.com/product/ ps://mesosphere.com/product/

  • htu

tups://open.mesosphere.com/ge ps://open.mesosphere.com/getu tuing-started/ ing-started/ datacenter/install/ datacenter/install/

  • htu

tups://www.digitalocean.com/community/ ps://www.digitalocean.com/community/ tutorials/how-to-con tutorials/how-to-confj fjgure-a-production-ready- gure-a-production-ready- mesosphere-cluster-on-ubuntu-14-04 mesosphere-cluster-on-ubuntu-14-04

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

SETUP A MINI-DATA-CENTER SETUP A MINI-DATA-CENTER 4 VMs , 1 Leader, 2 Slaves, 1 Admin 4 VMs , 1 Leader, 2 Slaves, 1 Admin

slide-17
SLIDE 17

THE “KERNEL”: MESOS THE “KERNEL”: MESOS 3 VMs , 1 Leader 3 VMs , 1 Leader

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

slide-18
SLIDE 18

THE “OS” : MARATHON THE “OS” : MARATHON ( it will start our ( it will start our microservices microservices ) )

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

slide-19
SLIDE 19

START A “SERVICE” IN THE “OS”: START A “SERVICE” IN THE “OS”: Hello-world Hello-world microservice microservice

{ "id": "hello-world", "container": { "type": "DOCKER", "docker": { "image": "tutum/hello-world", "forcePullImage": true, "network": "BRIDGE", "portMappings": [ { "containerPort": 80, "hostPort": 0, "protocol": "tcp" } ] } }, "cpus": 0.5, "mem": 512, "instances": 1 } curl "http://<marathon_url>/v2/apps" \

  • H "Content-Type: application/json" \
  • H "Accept:application/json" \
  • -data @/tmp/hello_world_app.json

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

slide-20
SLIDE 20

START A “SERVICE” IN THE “OS”: START A “SERVICE” IN THE “OS”: hello-world hello-world microservice microservice

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

slide-21
SLIDE 21

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY

  • DESIGN PRINCIPLES -
  • DESIGN PRINCIPLES -

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

Simple Scalable Secure Super fast

slide-22
SLIDE 22

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

OPENRESTY

  • Nginx Lua Module
  • Nginx Redis
  • Headers more
  • Set misc
  • LuaJIT
  • ….

Custom Modules

  • NAXSI – WAF
  • api-gateway request-

validation

  • api-gateway-async-logger

NGINX

  • Upstream
  • HTTP Proxy
  • PCRE
  • SSL
  • ….
slide-23
SLIDE 23

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Simple con Simple confj fjguration blending in Nginx guration blending in Nginx con confj fjguration guration

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

server { listen 80; server_name hello-world.api.container-con.org;

  • location / {

# ------------------------------------------------- # Specify what to validate for this location # ------------------------------------------------- set $validate_api_key on; set $validate_oauth_token on; set $validate_user_profile on; set $validate_service_plan on; ... # ------------------------------------------------- # Proxy the request to the actual microservice # ------------------------------------------------- proxy_pass $microservice$request_uri; } }

slide-24
SLIDE 24

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Service Discovery Example Service Discovery Example

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

server {
 listen 80;
 server_name ~^(?<app_name>.[^\.]+) \.api\.(?<domain>.+); … } hello-world .api.containercon.org

slide-25
SLIDE 25

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY ( OPENRESTY & NGINX based) ( OPENRESTY & NGINX based)

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

slide-26
SLIDE 26

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY DEPLOYMENT DEPLOYMENT

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

{ "id": "api-gateway", "container": { "type": "DOCKER", "docker": { "image": "adobeapiplatform/apigateway:latest", "forcePullImage": true, "network": "HOST" } }, "cpus": 4, "mem": 4028.0, "env": { "MARATHON_HOST": "http://<marathon_host>" }, "acceptedResourceRoles": ["slave_public"], "constraints": [ [ "hostname", "UNIQUE" ] ], "ports": [ 80 ], "instances": 1 } curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data '

slide-27
SLIDE 27

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY DEPLOYMENT DEPLOYMENT

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

{ "id": "api-gateway", "container": { "type": "DOCKER", "docker": { "image": "apiplatform/apigateway:latest", "forcePullImage": true, "network": "HOST" } }, "cpus": 4, "mem": 4028.0, "env": { "MARATHON_HOST": "http://<marathon_host>" }, "acceptedResourceRoles": ["slave_public"], "constraints": [ [ "hostname", "UNIQUE" ] ], "ports": [ 80 ], "instances": 1, <health_check_block> } curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' "healthChecks": [
 {
 "protocol": "HTTP",
 "portIndex": 0,
 "path": "/health-check",
 "gracePeriodSeconds": 3,
 "intervalSeconds": 10,
 "timeoutSeconds": 10
 }
 ] Optionally you can include health-check

slide-28
SLIDE 28

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

  • Demo: API KEY Management

Demo: API KEY Management

slide-29
SLIDE 29

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY API KEY Management with Redis API KEY Management with Redis

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' { "id": "api-gateway-redis", "container": { "type": "DOCKER", "docker": { "image": "redis:latest", "forcePullImage": true, "network": "HOST" } }, "cpus": 0.5, "mem": 1024.0, "constraints": [ [ "hostname", "UNIQUE" ] ], "ports": [ 6379 ], "instances": 1 }'

slide-30
SLIDE 30

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Protect a service with API-KEY Protect a service with API-KEY

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

set $marathon_app_name hello-world;

  • location / {

… # identify the service
 set $service_id $marathon_app_name;
 
 # identify the api key
 # either from the query params or from the "Api-Key" header
 set $api_key $arg_api_key;
 set_if_empty $api_key $http_x_api_key;
 
 # add the api-key validator
 set $validate_api_key on;
 
 # validate request
 access_by_lua "ngx.apiGateway.validation.validateRequest()";

  • proxy_pass http://$marathon_app_name$request_uri;

Create a new Vhost for server_name ~hello-world.api.(?<domain>.+);

slide-31
SLIDE 31

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Protect a service with API-KEY Protect a service with API-KEY

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

# ADD an API-KEY for the HELLO-WORLD service # NOTE: this API SHOULD not be exposed publicly

  • curl -X POST "http://api-gateway.${API_DOMAIN}/cache/api_key?key=key-1&\

app_name=app-1&\ service_id=hello-world&\ service_name=hello-world&\ consumer_org_name=demo-consumer"

  • # update hello-world microservice to require an API-KEY

curl "http://hello-world.${API_DOMAIN}/hello" # {"error_code":"403000","message":"Api Key is required"}

  • # make another call including the api-key

curl "http://hello-world.${API_DOMAIN}/hello" -H "X-Api-Key:key-1"

slide-32
SLIDE 32

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Capture Analytics Capture Analytics

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

  • Demo: Analytics using Graphite and

Demo: Analytics using Graphite and Grafana Grafana

slide-33
SLIDE 33

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Capture Analytics: update con Capture Analytics: update confj fjg g

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

set $marathon_app_name hello-world;

  • location / {

  • proxy_pass http://$marathon_app_name$request_uri;

# capture usage data log_by_lua ' if ( ngx.apiGateway.metrics ~= nil ) then ngx.apiGateway.metrics.captureUsageData() end ';

  • }
slide-34
SLIDE 34

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Capture Analytics Capture Analytics

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' { "id": "api-gateway-graphite", "container": { "type": "DOCKER", "docker": { "image": "hopsoft/graphite-statsd:latest", "forcePullImage": true, "network": "BRIDGE", "portMappings": [ { "containerPort": 80, "hostPort": 0, "protocol": "tcp" }, { "containerPort": 8125,"hostPort": 8125, "protocol": "udp"} ] } }, "cpus": 2, "mem": 4096.0, "instances": 1 }'

slide-35
SLIDE 35

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY Capture Analytics Capture Analytics

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

# verify that the Graphite instance is up by accessing it through the API Gateway curl "http://api-gateway-graphite.${API_DOMAIN}/render/? from=-5min&format=raw&target=carbon.aggregator.*.metricsReceived" # to open Graphite in a browser python -mwebbrowser "http://api-gateway-graphite.${API_DOMAIN}/"

  • # generate traffic for the hello-world service in order to capture metrics

docker run jordi/ab ab -k -n 10000 -c 500 "http://hello-world.${API_DOMAIN}/hello?api_key=key-1"

  • # then check the Graphite stats in the browser

python -mwebbrowser "http://api-gateway-graphite.${API_DOMAIN}/render/? from=-15min&format=png&target=stats_counts.publisher.*.consumer.demo- consumer.application.app-1.service.hello-world.sandbox.region.undefined.request.hello.GET.200.count"

slide-36
SLIDE 36

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY View Analytics with View Analytics with Grafana Grafana

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' { "id": "api-gateway-grafana", "container": { "type": "DOCKER", "docker": { "image": "grafana/grafana:latest", "forcePullImage": true, "network": "BRIDGE", "portMappings": [ { "containerPort": 3000, "hostPort": 0, "protocol": "tcp" } ] } }, "cpus": 1, "mem": 2048.0, "instances": 1 }'

slide-37
SLIDE 37

THE “TRAFFIC CTRL” : API GATEWAY THE “TRAFFIC CTRL” : API GATEWAY View Analytics with View Analytics with Grafana Grafana

Apache Apache Mesos Mesos & & Microservices Microservices #DEMO #DEMO

slide-38
SLIDE 38
slide-39
SLIDE 39

API Gateway is Open Source htups://github.com/adobe-apiplatform/apigateway

Gist script used in this presentation: htups://gist.github.com/ddragosd/608bf8d3d13e3f688874

slide-40
SLIDE 40