Recently, perhaps you hear too much about Microservices includes the concepts, cons, pros … I sure that you will ask yourself that how to implement it for your project? It is not easy to answer your question. In this post, i will tell you a part of my story after six month implement a social network project.
The story I would like to tell you is how to deploy a microservices with Docker Swarm and Consul (step by step instruction). With , my scenario, I have three nodes, installed Ubuntu 14.04 with 2G Ram and 2 CPUs. I used Vagrant and Virtualbox to build it.
As the image above, We will install Consul in all nodes. With, Node Gateway, It is installed Nginx to load-balance and used as a API Gateway for your services. And we also install Consul-Template to help you change Nginx configuration once there is an new service is on or down via Consul.
With Node Agent-One and Node Agent Two, we will use it as Swarm Clusters. So we will install Swarm, and run Swarm Join for all of them. Beside that, we have to install Consul and Registrator. Consul is a Service Discovery, and Registrator will help you announce for Consul know if there is any service is up or down.
There are many steps we need to do to build this system. So I deviced my post to three parts:
- Introduction Docker Swarm, Consul, Consul-Template, Registrator
- Install Nginx Load Balance with Consul Template, Swarm Cluster
- Replication and Scale with Swarm, Consul
I also publish all scripts to build this system to Github. You can check out it microservices-swarm-consul
So you just can download it and run:
Note: Make sure you installed Virtualbox and Vagrant in your machine. And if there is any issue in my code. Please report me. Thank you
Before you reading my series of the posts, you should read about the concept of the tools we will use for deploy microservices
Docker & Docker Swarm
Docker 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
- Service Discovery
- Key/Value Storage
- Failure Detection
- Multiple Datacenter
- Listen/Query the updates from Consul
- Updates Configuration File by the templates provided
- Executes commands
Registrator 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.
In next step, please go to Install Load Balance, API Gateway and Docker Swarm