This is a simple deployment of a high available application.
Docker Swarm is a Docker clustering solution, it turns multiple physical (or virtual) hosts into a one cluster, which practically behaves as a single Docker host. Swarm additionally gives you tools and mechiasms to easily scale your containers and create managed services with automatic load balancing to the exposed ports.
Swarm uses Raft Consensus Algortihm to manage the cluster state. Swarm can tolerate (N-1)/2
failures and needs (N/2)+1
nodes to agree on values.
- Ansible
- Vagrant
ansible-playbook -i inventory deploy.yml
vagrant destroy -f
The cluster provides an API call to http:///app When a POST request is sent to that API method, the application will store the timestamp into a database.
curl -X POST http://192.168.10.2/app
Expected output:
{
"epoch": 1510659852.600444,
"hostname": "ca425c25b7a9",
"records": 3,
"status": "saved",
"timestamp": "2017-11-14 11:44:12"
}
The container that is deployed in the workers is build with the files that are in the folder container
and published to http://cloud.docker.com/ from where is picked by the swarm to run it on the workers.
- Ansible
- Vagrant
- VirtualBox
- Ubuntu
- Docker
- Flask
- Python
- Redis
By default, 3 machines are created: manager
, worker1
, worker2
. You can adjust how many
workers you want in the Vagrantfile
, by setting the numworkers
variable. Manager, by default, has address "192.168.10.2", workers have consecutive IPs.
numworkers = 2
If your provisioner is VirtualBox
, you can modify the vm allocations for memory and cpu by changing these variables:
vmmemory = 512
numcpu = 1
MIT
Sergiu Marsavela @marsavela