27
techblog.newsweaver.com github.com/PierreVincent @PierreVincent pierrevincent Microservices, Docker & Service Discovery with Smartstack Meetup - Docker Rennes ISTIC, May 28th 2015 This work is licensed under a Creative Commons Attribution 4.0 International Li cense . newsweaver

Microservices, Docker & Service Discovery with Smartstack - English version

Embed Size (px)

Citation preview

Page 1: Microservices, Docker & Service Discovery with Smartstack - English version

techblog.newsweaver.com

github.com/PierreVincent

@PierreVincent

pierrevincent

Microservices, Docker & Service Discovery

with Smartstack

Meetup - Docker RennesISTIC, May 28th 2015

This work is licensed under a Creative Commons Attribution 4.0 International License.

newsweaver

Page 2: Microservices, Docker & Service Discovery with Smartstack - English version
Page 3: Microservices, Docker & Service Discovery with Smartstack - English version

MicroservicesDeployment

Build environment

Integration tests

Dev environment

Page 4: Microservices, Docker & Service Discovery with Smartstack - English version

Microservices are small, autonomous services that work together.

Sam NewmanBuilding Microservices

Page 5: Microservices, Docker & Service Discovery with Smartstack - English version

MonolithicApplication

Anchored in Technology

Complex code base

Refactoring is difficult

Disruptive deployment

Production issues are hard to isolate

Scaling options are limited

Page 6: Microservices, Docker & Service Discovery with Smartstack - English version

Small size=

High cohesion

Autonomy & isolation

=Low coupling

TechnologyHeterogeneity

Error isolation=

Resilience

Deployments with lower impact

Tailored scaling

Page 7: Microservices, Docker & Service Discovery with Smartstack - English version

+

Microservices

Cohesion1 container = 1 microservice

Technology HeterogeneityLanguage specific to the container

Delivery- Docker images (whatever the tech)- Docker registry

Low couplingEach container is independent

Simpler deploymentsOnly needs Docker

Orchestration solutions- More complex deployments- Swarm, Compose, Kubernetes, Mesos...

Page 8: Microservices, Docker & Service Discovery with Smartstack - English version

Test / Validation

Distributed Systems

ContinuousDelivery

MonitoringInterfaces between

services

Page 9: Microservices, Docker & Service Discovery with Smartstack - English version

What microservices boundaries

Everything on microservices Some reading...

Page 10: Microservices, Docker & Service Discovery with Smartstack - English version

Service DiscoveryDynamically wiring Microservices

Page 11: Microservices, Docker & Service Discovery with Smartstack - English version

Variable number of services Short life-span of services

How to locate the available services?

How to balance the requests to these

services?

What to do when a service is no longer

available?

Page 12: Microservices, Docker & Service Discovery with Smartstack - English version

❏ Registration / Lookup

❏ Load Balancing

❏ Transparency for clients

❏ Proactive error management

❏ Resistance to external problems

❏ No “Single Point of Failure”

Checklist

Page 13: Microservices, Docker & Service Discovery with Smartstack - English version

Recommendations Service

Viewing HistoryService

C*

.../users/123/recommendations

.../users/123/viewingHistory

{ “watched”: [ “Breaking Bad”, … ]}

{“recommendations”: [ { “watch”: “Better call saul!”, “because”: [“Breaking Bad”] }, ...]}

Page 14: Microservices, Docker & Service Discovery with Smartstack - English version

Recommendations Service

Viewing HistoryService

http://1.1.1.1/users/123/recommendations

services.properties

viewing_history_url = http://1.1.1.1

1.1.1.1

Solution 1: Config file

Clear list of services and instances

Possible to use shared volume with containers

Not really dynamic :- service must take changes into account- configuration must be updated

+

-

Page 15: Microservices, Docker & Service Discovery with Smartstack - English version

Recommendations Service

Viewing HistoryService

http://viewing-history/users/123/recommendations

/etc/hosts

1.1.1.1 viewing-history

1.1.1.1

Solution 2: Docker links

docker run --named=viewing-history viewing-history-service:latest

docker run --named=recommendations --link viewing-history:viewing-history recommendations-service:latest

Simple for the clients

Dependencies are clear

Possible deployment using docker-compose

Still not dynamic :- predefined order- harder for multiple instances

+

-

Page 16: Microservices, Docker & Service Discovery with Smartstack - English version

viewing-history.service → 1.1.1.1

Recommendations Service

Viewing HistoryService

http://viewing-history.service/users/123/recommendations

1.1.1.1

Solution 3: DNS

DNS

Simple for clients

Round-robin DNS:- multiples instances- load balancing

Propagation issues

+

-

Page 17: Microservices, Docker & Service Discovery with Smartstack - English version

[ viewing-history: 1.1.1.1 ...]

Recommendations Service

Viewing HistoryService

http://1.1.1.1/users/123/recommendations

1.1.1.1

Solution 4: Publisher / Subscriber

Key-valueStore

Dynamic :- each instance registers itself- clients discover the instances

Setup of a Key-value store

More complex for the services- Discovery logic coded in the services

+

-

Page 18: Microservices, Docker & Service Discovery with Smartstack - English version

[ viewing-history: 1.1.1.1 ...]

Recommendations Service

Viewing HistoryService

1.1.1.1

Solution 4: Publisher / Subscriber + Ambassador

Key-valueStore

http://1.1.1.1/users/123/recommendations

Very dynamic

Transparency for Clients and Providers

Setup of a Key-value Store

+

-

Page 19: Microservices, Docker & Service Discovery with Smartstack - English version

SmartstackDiscovery framework and integration with Docker

Page 20: Microservices, Docker & Service Discovery with Smartstack - English version

github.com/airbnb/nerve

github.com/airbnb/synapse

Page 21: Microservices, Docker & Service Discovery with Smartstack - English version

Zookeeper

Application

Viewing History Service

API Application

Recommendations Service

SynapseHAProxyNerve

Publication

Discovery

SmartstackOverview

Page 22: Microservices, Docker & Service Discovery with Smartstack - English version

Application

Nerve

ZK

1.1.1.1

nerve.confname = viewing_historyip = 1.1.1.1port = 8080healthCheck = /health

Publicatio

n

SmartstackNerve

API(8080)

/health

Viewing History Service

Page 23: Microservices, Docker & Service Discovery with Smartstack - English version

Application

Synapse

ZK

1.1.1.2

synapse.confviewing_history → 9000

Discov

ery

SmartstackSynapse

HAProxy

1.1.1.1

haproxy.confviewing_history: frontend: localhost:9000 backends: [1.1.1.1:8080]

GEThttp://localhost:9000/users/123/viewingHistory

8080 Servicesviewing_history: [1.1.1.1:8080]

Recommendations Service

ping

Page 24: Microservices, Docker & Service Discovery with Smartstack - English version

Distribution de base(ex. Ubuntu)

ruby

synapse (gem)

HA Proxy

nerve (gem)

service.jarsynapse.conf / nerve.conf

startup script

server.js + autres

startup script

Base Smartstack

startSynapse.sh

startNerve.sh

+ Tech

synapse.conf / nerve.conf + Service code+ Config

Page 25: Microservices, Docker & Service Discovery with Smartstack - English version

FROM newsweaver/smartstack-java

# DiscoveryADD nerve.conf.json /etc/ADD synapse.conf.json /etc/

# JARADD service.jar /opt/service/

# StartupADD start.sh /opt/start.shENTRYPOINT ["/opt/start.sh"]

Dockerfile

#!/bin/bash

/opt/startSynapse.sh/opt/startNerve.sh

java -jar /opt/service/service.jar

start.sh

$ docker build -t my-service ....$ docker run -d -e ZK_HOSTS=zk1:2181,zk2:2181 my-service

Page 26: Microservices, Docker & Service Discovery with Smartstack - English version

color-service

color-service

color-serviceGET .../v1/color

color-ui-service

blue

{ "name": "blue", "hex": "0000FF"}

{ "name": "red", "hex": "FF0000"}

{ "name": "green", "hex": "00FF00"}

Demo !github.com/PierreVincent/discovery-demo-color

Page 27: Microservices, Docker & Service Discovery with Smartstack - English version

techblog.newsweaver.com

Questions ?

@PierreVincent