+ All Categories
Home > Software > Microservices with docker swarm and consul

Microservices with docker swarm and consul

Date post: 06-Jan-2017
Category:
Upload: thanhson1085
View: 366 times
Download: 0 times
Share this document with a friend
20
Microservices with Docker Swarm and Consul
Transcript
Page 1: Microservices with docker swarm and consul

Microservices with Docker Swarm and Consul

Page 2: Microservices with docker swarm and consul
Page 3: Microservices with docker swarm and consul

Agenda

- Something about Microservices

- Implement Microservices with Docker Swarm and Consul

Page 4: Microservices with docker swarm and consul
Page 5: Microservices with docker swarm and consul
Page 6: Microservices with docker swarm and consul
Page 7: Microservices with docker swarm and consul
Page 8: Microservices with docker swarm and consul
Page 9: Microservices with docker swarm and consul

“You shouldn't start a new project with microservices, even if you're sure your application will be big enough to make it worthwhile”(Martin Fowler)

Page 10: Microservices with docker swarm and consul
Page 11: Microservices with docker swarm and consul

Some SuggestionsPrograming: Python, NodeJS, Golang*

Orchestration: Docker, Docker Swarm, Consul, Consul-Template, Registrator, CoreOS*

Databases & Caches: PosgreSQL, Cassanda, ElasticSearch, Redis

Load Balancer & API Gateway: Nginx

Queues: Kafka

CI/CD: Jenkins, Ansible

Monitors: Grafana + InfluxDB + (CollectD, cAdvisor)

Logs: Kibana + ElasticSearch + FluentD

Data Center: AWS EC2, AWS S3, AWS Float IP, Cloudfront

CDN & DNS & DDOS Protection: Cloudflare

Documents: Swagger, Markdown, mkdocs

Page 12: Microservices with docker swarm and consul

Backend System Suggestions

Page 13: Microservices with docker swarm and consul

An Example

Node Gateway will be used a API Gateway and Load Balancer

Node Agent One, Node Agent Two will be used to run services that are able to scale.

Page 14: Microservices with docker swarm and consul

Docker & Docker SwarmDocker is a platform for developers and sysadmins to develop, ship, and run applications. Docker lets you quickly assemble applications from components and eliminates the friction that can come when shipping code. Docker lets you get your code tested and deployed into production as fast as possible.

Docker Swarm is native clustering for Docker. It allows you create and access to a pool of Docker hosts using the full suite of Docker tools. Because Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts

#install

$ docker pull swarm

#run joiner

$ docker run -d swarm join \ --addr=172.20.20.11:2375 \ token://acdb9dfa3ea6da0b0cfb2c819385fcd3

#run manager

$ docker run -d -p 12375:2375 \swarm manage \token://acdb9dfa3ea6da0b0cfb2c819385fcd3

Page 15: Microservices with docker swarm and consul

Consul and Consul-TemplateConsul

- Service Discovery

- Key/Value Storage

- Failure Detection

- Multiple Datacenter

Consul-Template

- Listen/Query the updates from Consul

- Updates Configuration File by the templates provided

- Executes commands

#run a consul agent$ consul agent -data-dir /tmp/consul -node=agent-one \ -bind=172.20.20.11 -client=0.0.0.0 \

-config-dir /etc/consul.d \ -retry-join 172.20.20.10

#run consul-templateexec consul-template \ -consul 127.0.0.1:8500 \ -template "/build/gateway/consul-template/nginx.ctmpl:/etc/nginx/sites-available/default:service nginx reload" \ -retry 30s

Page 16: Microservices with docker swarm and consul

RegistratorRegistrator automatically registers and deregisters services for any Docker container by inspecting containers as they come online. Registrator supports pluggable service registries, which currently includes Consul, etcd and SkyDNS 2.

#run registrator

$ docker run -d \ --name=registrator --net=host \ --volume=/var/run/docker.sock:/tmp/docker.sock \ gliderlabs/registrator:latest \ consul://localhost:8500

Page 17: Microservices with docker swarm and consul

A Scenario

At the beginning, Service #1 only runs in Node 2.

After that Service #1 scales to Node 2

Via Docker API, Registrator will know the appearance of Service #1 on Node 2.

Registrator will register Service #1 with Consul.

In the meanwhile, Consul-Template in listening Consul. So Consul-Template will know the new service is up in Node 2. Finally, Consul-Template will trigger a reload command to Nginx add the new service into load balancer.

Page 18: Microservices with docker swarm and consul

DEMOhttps://github.com/thanhson1085/microservices-swarm-consul

Page 19: Microservices with docker swarm and consul

MICROSERVICES

DEVOPS

Page 20: Microservices with docker swarm and consul

References

http://martinfowler.com

http://microservices.io/patterns/

https://www.sequoiacap.com/article/build-us-microservices/

https://sonnguyen.ws/microservices-with-docker-swarm-and-consul/


Recommended