Top Banner
CloudConf Turin 16th March 2017 Deploy, scale and coordinate a microservice oriented application cloudconf.it
40

CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Apr 05, 2017

Download

Software

Corley S.r.l.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

CloudConfTurin 16th March 2017

Deploy, scale and coordinate a microservice orientedapplication

cloudconf.it

Page 2: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Walter Dal Mut

walter.dalmut @ corley.itSolution Architect @

Corley

Page 3: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Microservices

Page 4: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

They're coming outta the walls

Page 5: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Docker Swarm

Page 6: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Issue a new process (deploy)$ docker service create \ --name app \ registry.walterdalmut.com/app:v1

$ ./app &

Page 7: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Run different processes (scale)$ docker service scale app=10 $ ./app &

$ ./app & $ ./app &

Page 8: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

What about the locking system?In a distributed system: locks (distributed locks) are

the foundations for activity synchronization

Page 9: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

What about coordination?

Page 10: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

A service have its own con�guration atlaunch I am here with this address, port etc...

A service require other servicecon�gurations Where the database is, which password i should use, etc...

The service should reports its owns status I am alive and responsive (for healthcheck) other services can check the health report for the maintenance mode or to shortcircuit the service dependency

Page 11: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

To expose the coordination problem we create anapplication

Page 12: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Read the twitter stream

#cloudconf2017

Page 13: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

users that tweet with this handle create a reserved API service [ JSON over HTTP ]

GET /tweet - list my tweetsPOST /tweet - record a newtweet

The database to store tweets is self-contained in the API service

Page 14: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Now every service is exposed with a unique pairaddress:port in the swarm

Page 15: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

every box is a container (service)blinks for activities (publish new tweets)

Page 16: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Multiple services(1)(1)

(1..*)

(n)

(1..*)

Stream readererDistributed queueService Worker (need a distributed lock)

a lock identi�es the service deploymentprogresson missing => service deployon existing => publish messages

Per user containerA proxy to list users and redirects requests

Page 17: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

HTTP framework> GET /user/walterdalmut HTTP/1.1 > Host: cluster.corsi.walterdalmut.com:30000 > User-Agent: curl/7.47.0 > Accept: */*

< HTTP/1.1 302 Found < location: http://cluster.corsi.walterdalmut.com:30002/v1/tweet < vary: origin< cache-control: no-cache < content-length: 0< Date: Sun, 12 Mar 2017 11:26:50 GMT < Connection: keep-alive

Page 18: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

CloudConf2017 Example

Page 19: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
Page 20: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
Page 21: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Every user have its own network address andportEvery user expose its own API

How do we connect services together?

Page 22: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

DNS as a coordination systemDNS is a good solution to point things in a network

DNS SRV expose a service address con�guration$ dig srv _auth._tcp.walterdalmut.com +short 1 10 8080 1.api.walterdalmut.com 1 10 8080 2.api.walterdalmut.com

Page 23: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

And service con�gurations?host: db.mynet.local port: 3306 username: root password: root dbname: example

Page 24: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

K / VSeveral coordination systems available

Etcd is one of the most interesting coordination system available Consul integrates di�erent things together like: DNS, KV, etc...

many other: zookeeper, etc...

Page 25: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Redis as a coordination service

Page 26: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

distribute con�gurations at paths$ cat mydb.conf | redis-cli set /path/to/disk/mydb.conf -

Page 27: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Where is my `ls` command now?$ redis-cli keys /path/* 1) "/path/to/disk/mydb.conf"

Page 28: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Get my con�guration back$ redis-cli get /path/to/disk/mydb.conf host: db.mynet.local port: 3306 username: root password: root dbname: example

Page 29: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

How to report the application status?Healthchecks

Page 30: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Con�gurations can also expiresDead man switch

application reports continuously

cat mydb.conf | SETEX /path/to/disk/mydb.conf 30 -

EXPIRE /path/to/disk/mydb.conf 30 ... sleep 20 EXPIRE /path/to/disk/mydb.conf 30 ...

Page 31: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Services links togetherCan i watch for con�guration changes?

refresh my services on updates

Page 32: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Redis Keyspace Noti�cations

or in your con�guration �le

CONFIG SET notify-keyspace-events AKE

Page 33: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Listen for my con�guration changesSUBSCRIBE __keyspace@0__:/path/to/disk/mydb.conf

Page 34: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Here the event$ cat mydb.conf | redis-cli set /path/to/disk/mydb.conf -

1) "message" 2) "__keyspace@0__:/path/to/disk/mydb.conf" 3) "set"

Page 35: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Distributed locksIn a single node for redis

NX - if not exists PX 30000 - expires in 30000 ms

SET /etc/lock/username/.lock {random_value} NX PX 30000

Page 36: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

After 30 seconds the lock expires

SET /etc/lock/walterdalmut/.lock 3891573 NX PX 30000 OK SET /etc/lock/walterdalmut/.lock 2857152 NX PX 30000 (nil)

Page 37: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

How do i release the lock?DEL /etc/lock/walterdalmut/.lock

Page 38: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

How do i extend the lock?EXPIRE /etc/lock/walterdalmut/.lock 30

Page 39: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

How do i watch for lock release?

Lock releasesSUBSCRIBE __keyspace@0__:/etc/lock/walterdalmut/.lock

1) "message" 2) "__keyspace@0__:/etc/lock/walterdalmut/.lock" 3) "del"

1) "message" 2) "__keyspace@0__:/etc/lock/walterdalmut/.lock" 3) "expired"

Page 40: CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application

Thank you for listening