Provision a Docker Swarm cluster composed of two masters and two workers using Vagrant and Ansible.
To create all the virtual machines and provision with the default swarm stacks execute:
vagrant plugin install vagrant-hostmanager
vagrant up
On Windows take a look at:
If the provision of the swarm stack fails you can execute only the provision part:
vagrant provision
If you want to add more hosts (masters and/or workers) just edit both files:
- Vagrantfile
- ansible/inventory
After that just run
vagrant up --provision
After this you can connect to one of the master nodes and check the cluster status
vagrant ssh swarm-master-1
docker node ls
This project has docker-compose files to create swarm stacks. The following stacks are available:
- Traefik/Consul Stack
- Web User Interface Stack
- Automation Stack
Web User Interface Stack provides the following:
DevOps Tool | URL | Description |
---|---|---|
Swarmpit | http://swarm-master-1:888 | Operate your docker infrastructure like a champ |
Portainer | http://swarm-master-1:9000 | Lightweight Docker Swarm management UI |
There are 2 docker-compose files:
- docker-compose.swarmpit.yml (this is automatically installed)
- docker-compose.portainer.yml
You can also install all the stack and use traefik. This stack uses traefik and consul and handles HTTPS certificates automatically (including renewals) with Let's Encrypt.
To install the traefik stack run the following commands on the swarm manager:
vagrant ssh swarm-master-1
docker stack rm web_ui
docker stack rm automation
Edit the environment variables under ansible/traefik_consul-playbook.yml
and execute the playbook
ansible-playbook -i ansible/inventory ansible/deploy-traefik-stack.yml --tags traefik
If you want to use docker-compose outside ansible you need to define some environment variables
vagrant@swarm-master-1:~$ export DOMAIN=intra.local.com
vagrant@swarm-master-1:~$ export USERNAME=admin
vagrant@swarm-master-1:~$ export PASSWORD=admin
vagrant@swarm-master-1:~$ export HASHED_PASSWORD=$(openssl passwd -apr1 $PASSWORD)
vagrant@swarm-master-1:~$ docker stack deploy -c docker-compose.swarmpit.traefik.yml web_ui
Make sure you have the following DNS entries:
DevOps Tool | URL |
---|---|
Traefik | http://traefik.intra.local.com |
Consul | http://consul.intra.local.com |
Swarmpit | http://swarmpit.intra.local.com |
Portainer | http://portainer.intra.local.com |
- Vagrantfile reads nodes from ansible/inventory
- Use traefik.toml file to configure traefik
- Add Portworx support for persistent storage (https://portworx.com/use-case/docker-persistent-storage/)