SlideShare a Scribd company logo
www.eleven-labs.com
WORKSHOP
Factory
Vincent Composieux
@vcomposieux
… to beyond and
CONSULSERVICE DISCOVERY
&
FAILURE DETECTION
2013
FIRST COMMIT
WHAT ABOUT CONSUL?
Open-source & built by HashiCorp.
“Consul has multiple components,
but as a whole, it is a tool for
discovering and configuring
services in your infrastructure.”
GO
WRITTEN
WHAT ABOUT CONSUL?
FRONT 01 FRONT 02 FRONT 03
Terminal
$ curl http://frontend.eleven-labs.com ..
DNS API
UP UPDOWN
WHAT ABOUT CONSUL?
SERVICE DISCOVERY
➔ Register new services via configuration or API
➔ Access all available services or a specific one
➔ Updates automatically when new services are
available or not
FAILURE DETECTION
➔ Updates automatically Consul services when
a service is down
➔ Manages services states (we can put a
service in maintenance for instance)
CONSENSUS
PROTOCOL
http://thesecretlivesofdata.com/raft/
WHAT ABOUT CONSUL?
GOSSIP
PROTOCOL
This is for consistency:
nodes inherit from a state:
follower, candidate or
leader.
Propagation of information (epidemy)
WHAT ABOUT CONSUL?
8600
DNS
8500
HTTP
8300
8400
RPC
Use port 8300 (TCP only) but also:
➔ 8301 (TCP/UDP, Gossip over LAN)
➔ 8302 (TCP/UDP, Gossip over WAN)
This port exposes:
➔ A web UI
➔ A HTTP API
This port is used for DNS server.
Possible to override with --dns-port
WHAT ABOUT CONSUL?
https://demo.consul.io
WEB UI LOOKS LIKE THIS
SERVICE DISCOVERY
HANDS ON
swarm
→ registrator
→ ekofr/http-ip
swarm
→ registrator
→ ekofr/http-ip
ARCHITECTURE
CONSUL
(Machine / Swarm Discovery)
NODE #01
(Machine / Master)
NODE #02
(Machine)
HTTP DNS
1
2 33
DOCKER
MACHINES
1
SWARM
CLUSTER
7
DOCKER
CONTAINERS
CONSUL > Machine
Terminal
$ docker-machine create -d virtualbox consul ..
Create the “consul-master” machine under Docker,
using the Virtualbox driver.
CONSUL
(Machine)
CONSUL > Container
Terminal
$ eval $(docker-machine env consul)
$ docker run -d 
-p 8301:8301 
-p 8302:8302 
-p 8400:8400 
-p 8500:8500 
-p 53:8600/udp consul ..
Enter your consul-master environment and run the
“consul” Docker image (as server).
CONSUL
(Machine)
NODE #01 > Machine (New tab)
Terminal
$ docker-machine create -d virtualbox 
--swarm 
--swarm-master 
--swarm-discovery="consul://$(docker-machine ip consul):8500" 
--engine-opt="cluster-store=consul://$(docker-machine ip
consul):8500" 
--engine-opt="cluster-advertise=eth1:2376" swarm-node-01 ..
Create the “swarm-node-01” machine under Docker
and map Swarm discovery with Consul.
CONSUL
(Machine)
NODE #01
NODE #01 > Registrator
Terminal
$ eval $(docker-machine env swarm-node-01)
$ docker run -d 
--volume=/var/run/docker.sock:/tmp/docker.sock 
gliderlabs/registrator 
-ip $(docker-machine ip swarm-node-01) 
consul://$(docker-machine ip consul):8500 ..
Enter “swarm-node-01” machine and run a
Registrator Docker image as a daemon.
CONSUL
(Machine)
NODE #01
NODE #01 > HTTP Container
Terminal
$ docker network create 
--subnet=172.18.0.0/16 network-node-01
$ docker run -d 
--net network-node-01 
-p 80:8080 
ekofr/http-ip ..
Create a “network-node-01” Docker network and run
“ekofr/http-ip” using this network.
CONSUL
(Machine)
NODE #01
NODE #02 > Machine (New tab)
Terminal
$ docker-machine create -d virtualbox 
--swarm 
--swarm-discovery="consul://$(docker-machine ip consul):8500" 
--engine-opt="cluster-store=consul://$(docker-machine ip
consul):8500" 
--engine-opt="cluster-advertise=eth1:2376" swarm-node-02 ..
Create the “swarm-node-02” machine under Docker
and map Swarm discovery with Consul.
CONSUL
(Machine)
NODE #01 NODE #02
NODE #02 > Registrator
Terminal
$ eval $(docker-machine env swarm-node-02)
$ docker run -d 
--volume=/var/run/docker.sock:/tmp/docker.sock 
gliderlabs/registrator 
-ip $(docker-machine ip swarm-node-02) 
consul://$(docker-machine ip consul):8500 ..
Enter “swarm-node-02” machine and run a
Registrator Docker image as a daemon.
CONSUL
(Machine)
NODE #01 NODE #02
NODE #02 > HTTP Container
Terminal
$ docker network create 
--subnet=172.19.0.0/16 network-node-02
$ docker run -d 
--net network-node-02 
-p 80:8080 
ekofr/http-ip ..
Create a “network-node-02” Docker network and run
“ekofr/http-ip” using this network.
CONSUL
(Machine)
NODE #01 NODE #02
What’s happening on DNS?
Terminal
$ dig @$(docker-machine ip consul) http-ip.service.consul ..
;; QUESTION SECTION:
;http-ip.service.consul. IN A
;; ANSWER SECTION:
http-ip.service.consul. 0 IN A 192.168.99.100
http-ip.service.consul. 0 IN A 192.168.99.102
Let’s make a DNS call to ensure that our “http-ip”
service is available under 2 machines! Shutdown them!
DNS
What’s happening on DNS?
Terminal
$ dig @$(docker-machine ip consul) http-ip.service.consul SRV ..
;; ANSWER SECTION:
http-ip.service.consul. 0 IN SRV 1 1 80 c0a86366.addr.dc1.consul.
http-ip.service.consul. 0 IN SRV 1 1 80 c0a86364.addr.dc1.consul.
SRV records allows to define a priority and a weight for DNS
entries but it is not supported by Consul at this time.
You can find more information on SRV records on Wikipedia.
Add DNS to your system
Let’s make an HTTP call to ensure that both nodes
answers. Add Consul DNS server as a resolver.
CONSUL
(Machine)
Call HTTP service
Terminal
$ curl http://http-ip.service.consul
hello from 172.18.0.2
$ curl http://http-ip.service.consul ..
hello from 172.19.0.2
Now, perform your HTTP request and confirm that you are
balanced between your two machines.
HTTP DNS
FAILURE DETECTION
HANDS ON
NODE #01 > Add a HTTP check
Terminal
$ eval $(docker-machine env swarm-node-01)
$ docker kill 
$(docker ps -q --filter='ancestor=ekofr/http-ip') ..
First, kill the docker container that runs ekofr/http-ip.
We will launch it just after with a health check.
NODE #01 > Add a HTTP check
Terminal
$ docker run -d 
--net network-node-01 -p 80:8080 
-e SERVICE_CHECK_SCRIPT="curl -s -f http://$(docker-machine ip
swarm-node-01)" 
-e SERVICE_CHECK_INTERVAL=5s 
-e SERVICE_CHECK_TIMEOUT=1s 
ekofr/http-ip ..
Add a check to the ekofr/http-ip container.
We add a HTTP check here but it could be what you want.
More information about Registrator available environment variables here.
More information on Consul check definition here.
NODE #02 > Add a HTTP check
Terminal
$ eval $(docker-machine env swarm-node-02)
$ docker kill 
$(docker ps -q --filter='ancestor=ekofr/http-ip') ..
First, kill the docker container that runs ekofr/http-ip.
We will launch it just after with a health check.
NODE #02 > Add a HTTP check
Terminal
$ docker run -d 
--net network-node-02 -p 80:8080 
-e SERVICE_CHECK_SCRIPT="curl -s -f http://$(docker-machine ip
swarm-node-02)" 
-e SERVICE_CHECK_INTERVAL=5s 
-e SERVICE_CHECK_TIMEOUT=1s 
ekofr/http-ip ..
Add a check to the ekofr/http-ip container.
We add a HTTP check here but it could be what you want.
More information about Registrator available environment variables here.
More information on Consul check definition here.
Check services health via web UI
If you launch the UI, you should see your health checks:
Check services health via API
Terminal
$ curl http://$(docker-machine ip consul):8500/v1/health/checks/http-ip ..
[
{
"Status": "passing",
"Output": "hello from 172.18.0.2",
"ServiceName": "http-ip",
},
…
]
Note that you can also check your services’s health via the
Consul API “/health” endpoint:
THANK YOU

More Related Content

What's hot (20)

PDF
Server(less) Swift at SwiftCloudWorkshop 3
kognate
 
PDF
Microservices blue-green-deployment-with-docker
Kidong Lee
 
PPTX
Solving anything in VCL
Fastly
 
PPTX
A complete guide to Node.js
Prabin Silwal
 
PDF
Advanced VCL: how to use restart
Fastly
 
PDF
Getting Started with Consul
Ramit Surana
 
PDF
Service discovery like a pro (presented at reversimX)
Eran Harel
 
PDF
VCL template abstraction model and automated deployments to Fastly
Fastly
 
PDF
Altitude SF 2017: Debugging Fastly VCL 101
Fastly
 
PDF
openstack源码分析(1)
cannium
 
PDF
Test driven infrastructure
Skills Matter Talks
 
PPTX
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
Julian Dunn
 
PPTX
An intro to Docker, Terraform, and Amazon ECS
Yevgeniy Brikman
 
PDF
Puppet in the Pipeline
Puppet
 
PDF
OpenNebula and SaltStack - OpenNebulaConf 2013
databus.pro
 
PDF
Autoscaling with hashi_corp_nomad
Bram Vogelaar
 
PPTX
Deployment with capistrano
sagar junnarkar
 
PDF
Altitude NY 2018: Programming the edge workshop
Fastly
 
PDF
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
PDF
A user's perspective on SaltStack and other configuration management tools
SaltStack
 
Server(less) Swift at SwiftCloudWorkshop 3
kognate
 
Microservices blue-green-deployment-with-docker
Kidong Lee
 
Solving anything in VCL
Fastly
 
A complete guide to Node.js
Prabin Silwal
 
Advanced VCL: how to use restart
Fastly
 
Getting Started with Consul
Ramit Surana
 
Service discovery like a pro (presented at reversimX)
Eran Harel
 
VCL template abstraction model and automated deployments to Fastly
Fastly
 
Altitude SF 2017: Debugging Fastly VCL 101
Fastly
 
openstack源码分析(1)
cannium
 
Test driven infrastructure
Skills Matter Talks
 
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
Julian Dunn
 
An intro to Docker, Terraform, and Amazon ECS
Yevgeniy Brikman
 
Puppet in the Pipeline
Puppet
 
OpenNebula and SaltStack - OpenNebulaConf 2013
databus.pro
 
Autoscaling with hashi_corp_nomad
Bram Vogelaar
 
Deployment with capistrano
sagar junnarkar
 
Altitude NY 2018: Programming the edge workshop
Fastly
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
A user's perspective on SaltStack and other configuration management tools
SaltStack
 

Similar to Workshop Consul .- Service Discovery & Failure Detection (20)

PPTX
Simple docker hosting in FIWARE Lab
Fernando Lopez Aguilar
 
PPTX
Docker Security workshop slides
Docker, Inc.
 
PDF
Chris Swan ONUG Academy - Container Networks Tutorial
Cohesive Networks
 
PPTX
Running Docker in Development & Production (#ndcoslo 2015)
Ben Hall
 
PDF
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
PROIDEA
 
PDF
Deploying and Scaling a Rails Application with Docker and Friends
Invisiblelines
 
PDF
Fullstack conf 2017 - Basic dev pipeline end-to-end
Ezequiel Maraschio
 
PPTX
Running Docker in Development & Production (DevSum 2015)
Ben Hall
 
PDF
Continuous Delivery: The Next Frontier
Carlos Sanchez
 
PDF
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
謝 宗穎
 
PPTX
Integrating Consul and Puppet
Dylan Cochran
 
PDF
Integrating Consul and Puppet
OnyxPoint Inc
 
PDF
Higher order infrastructure: from Docker basics to cluster management - Nicol...
Codemotion
 
PPTX
Start tracking your ruby infrastructure
Sergiy Kukunin
 
PDF
The state of the swarm
Mathieu Buffenoir
 
PPTX
Harmonious Development: Via Vagrant and Puppet
Achieve Internet
 
PDF
Burn down the silos! Helping dev and ops gel on high availability websites
Lindsay Holmwood
 
PDF
Create and use a Dockerized Aruba Cloud server - CloudConf 2017
Aruba S.p.A.
 
PDF
Things I've learned working with Docker Support
Sujay Pillai
 
PDF
Framework Agnostic Discovery
KubeAcademy
 
Simple docker hosting in FIWARE Lab
Fernando Lopez Aguilar
 
Docker Security workshop slides
Docker, Inc.
 
Chris Swan ONUG Academy - Container Networks Tutorial
Cohesive Networks
 
Running Docker in Development & Production (#ndcoslo 2015)
Ben Hall
 
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
PROIDEA
 
Deploying and Scaling a Rails Application with Docker and Friends
Invisiblelines
 
Fullstack conf 2017 - Basic dev pipeline end-to-end
Ezequiel Maraschio
 
Running Docker in Development & Production (DevSum 2015)
Ben Hall
 
Continuous Delivery: The Next Frontier
Carlos Sanchez
 
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
謝 宗穎
 
Integrating Consul and Puppet
Dylan Cochran
 
Integrating Consul and Puppet
OnyxPoint Inc
 
Higher order infrastructure: from Docker basics to cluster management - Nicol...
Codemotion
 
Start tracking your ruby infrastructure
Sergiy Kukunin
 
The state of the swarm
Mathieu Buffenoir
 
Harmonious Development: Via Vagrant and Puppet
Achieve Internet
 
Burn down the silos! Helping dev and ops gel on high availability websites
Lindsay Holmwood
 
Create and use a Dockerized Aruba Cloud server - CloudConf 2017
Aruba S.p.A.
 
Things I've learned working with Docker Support
Sujay Pillai
 
Framework Agnostic Discovery
KubeAcademy
 
Ad

Recently uploaded (20)

PPTX
internet básico presentacion es una red global
70965857
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PPTX
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPT
introductio to computers by arthur janry
RamananMuthukrishnan
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
internet básico presentacion es una red global
70965857
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
Orchestrating things in Angular application
Peter Abraham
 
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
introductio to computers by arthur janry
RamananMuthukrishnan
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
Ad

Workshop Consul .- Service Discovery & Failure Detection

  • 1. www.eleven-labs.com WORKSHOP Factory Vincent Composieux @vcomposieux … to beyond and CONSULSERVICE DISCOVERY & FAILURE DETECTION
  • 2. 2013 FIRST COMMIT WHAT ABOUT CONSUL? Open-source & built by HashiCorp. “Consul has multiple components, but as a whole, it is a tool for discovering and configuring services in your infrastructure.” GO WRITTEN
  • 3. WHAT ABOUT CONSUL? FRONT 01 FRONT 02 FRONT 03 Terminal $ curl http://frontend.eleven-labs.com .. DNS API UP UPDOWN
  • 4. WHAT ABOUT CONSUL? SERVICE DISCOVERY ➔ Register new services via configuration or API ➔ Access all available services or a specific one ➔ Updates automatically when new services are available or not FAILURE DETECTION ➔ Updates automatically Consul services when a service is down ➔ Manages services states (we can put a service in maintenance for instance)
  • 5. CONSENSUS PROTOCOL http://thesecretlivesofdata.com/raft/ WHAT ABOUT CONSUL? GOSSIP PROTOCOL This is for consistency: nodes inherit from a state: follower, candidate or leader. Propagation of information (epidemy)
  • 6. WHAT ABOUT CONSUL? 8600 DNS 8500 HTTP 8300 8400 RPC Use port 8300 (TCP only) but also: ➔ 8301 (TCP/UDP, Gossip over LAN) ➔ 8302 (TCP/UDP, Gossip over WAN) This port exposes: ➔ A web UI ➔ A HTTP API This port is used for DNS server. Possible to override with --dns-port
  • 9. swarm → registrator → ekofr/http-ip swarm → registrator → ekofr/http-ip ARCHITECTURE CONSUL (Machine / Swarm Discovery) NODE #01 (Machine / Master) NODE #02 (Machine) HTTP DNS 1 2 33 DOCKER MACHINES 1 SWARM CLUSTER 7 DOCKER CONTAINERS
  • 10. CONSUL > Machine Terminal $ docker-machine create -d virtualbox consul .. Create the “consul-master” machine under Docker, using the Virtualbox driver. CONSUL (Machine)
  • 11. CONSUL > Container Terminal $ eval $(docker-machine env consul) $ docker run -d -p 8301:8301 -p 8302:8302 -p 8400:8400 -p 8500:8500 -p 53:8600/udp consul .. Enter your consul-master environment and run the “consul” Docker image (as server). CONSUL (Machine)
  • 12. NODE #01 > Machine (New tab) Terminal $ docker-machine create -d virtualbox --swarm --swarm-master --swarm-discovery="consul://$(docker-machine ip consul):8500" --engine-opt="cluster-store=consul://$(docker-machine ip consul):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-node-01 .. Create the “swarm-node-01” machine under Docker and map Swarm discovery with Consul. CONSUL (Machine) NODE #01
  • 13. NODE #01 > Registrator Terminal $ eval $(docker-machine env swarm-node-01) $ docker run -d --volume=/var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator -ip $(docker-machine ip swarm-node-01) consul://$(docker-machine ip consul):8500 .. Enter “swarm-node-01” machine and run a Registrator Docker image as a daemon. CONSUL (Machine) NODE #01
  • 14. NODE #01 > HTTP Container Terminal $ docker network create --subnet=172.18.0.0/16 network-node-01 $ docker run -d --net network-node-01 -p 80:8080 ekofr/http-ip .. Create a “network-node-01” Docker network and run “ekofr/http-ip” using this network. CONSUL (Machine) NODE #01
  • 15. NODE #02 > Machine (New tab) Terminal $ docker-machine create -d virtualbox --swarm --swarm-discovery="consul://$(docker-machine ip consul):8500" --engine-opt="cluster-store=consul://$(docker-machine ip consul):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-node-02 .. Create the “swarm-node-02” machine under Docker and map Swarm discovery with Consul. CONSUL (Machine) NODE #01 NODE #02
  • 16. NODE #02 > Registrator Terminal $ eval $(docker-machine env swarm-node-02) $ docker run -d --volume=/var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator -ip $(docker-machine ip swarm-node-02) consul://$(docker-machine ip consul):8500 .. Enter “swarm-node-02” machine and run a Registrator Docker image as a daemon. CONSUL (Machine) NODE #01 NODE #02
  • 17. NODE #02 > HTTP Container Terminal $ docker network create --subnet=172.19.0.0/16 network-node-02 $ docker run -d --net network-node-02 -p 80:8080 ekofr/http-ip .. Create a “network-node-02” Docker network and run “ekofr/http-ip” using this network. CONSUL (Machine) NODE #01 NODE #02
  • 18. What’s happening on DNS? Terminal $ dig @$(docker-machine ip consul) http-ip.service.consul .. ;; QUESTION SECTION: ;http-ip.service.consul. IN A ;; ANSWER SECTION: http-ip.service.consul. 0 IN A 192.168.99.100 http-ip.service.consul. 0 IN A 192.168.99.102 Let’s make a DNS call to ensure that our “http-ip” service is available under 2 machines! Shutdown them! DNS
  • 19. What’s happening on DNS? Terminal $ dig @$(docker-machine ip consul) http-ip.service.consul SRV .. ;; ANSWER SECTION: http-ip.service.consul. 0 IN SRV 1 1 80 c0a86366.addr.dc1.consul. http-ip.service.consul. 0 IN SRV 1 1 80 c0a86364.addr.dc1.consul. SRV records allows to define a priority and a weight for DNS entries but it is not supported by Consul at this time. You can find more information on SRV records on Wikipedia.
  • 20. Add DNS to your system Let’s make an HTTP call to ensure that both nodes answers. Add Consul DNS server as a resolver. CONSUL (Machine)
  • 21. Call HTTP service Terminal $ curl http://http-ip.service.consul hello from 172.18.0.2 $ curl http://http-ip.service.consul .. hello from 172.19.0.2 Now, perform your HTTP request and confirm that you are balanced between your two machines. HTTP DNS
  • 23. NODE #01 > Add a HTTP check Terminal $ eval $(docker-machine env swarm-node-01) $ docker kill $(docker ps -q --filter='ancestor=ekofr/http-ip') .. First, kill the docker container that runs ekofr/http-ip. We will launch it just after with a health check.
  • 24. NODE #01 > Add a HTTP check Terminal $ docker run -d --net network-node-01 -p 80:8080 -e SERVICE_CHECK_SCRIPT="curl -s -f http://$(docker-machine ip swarm-node-01)" -e SERVICE_CHECK_INTERVAL=5s -e SERVICE_CHECK_TIMEOUT=1s ekofr/http-ip .. Add a check to the ekofr/http-ip container. We add a HTTP check here but it could be what you want. More information about Registrator available environment variables here. More information on Consul check definition here.
  • 25. NODE #02 > Add a HTTP check Terminal $ eval $(docker-machine env swarm-node-02) $ docker kill $(docker ps -q --filter='ancestor=ekofr/http-ip') .. First, kill the docker container that runs ekofr/http-ip. We will launch it just after with a health check.
  • 26. NODE #02 > Add a HTTP check Terminal $ docker run -d --net network-node-02 -p 80:8080 -e SERVICE_CHECK_SCRIPT="curl -s -f http://$(docker-machine ip swarm-node-02)" -e SERVICE_CHECK_INTERVAL=5s -e SERVICE_CHECK_TIMEOUT=1s ekofr/http-ip .. Add a check to the ekofr/http-ip container. We add a HTTP check here but it could be what you want. More information about Registrator available environment variables here. More information on Consul check definition here.
  • 27. Check services health via web UI If you launch the UI, you should see your health checks:
  • 28. Check services health via API Terminal $ curl http://$(docker-machine ip consul):8500/v1/health/checks/http-ip .. [ { "Status": "passing", "Output": "hello from 172.18.0.2", "ServiceName": "http-ip", }, … ] Note that you can also check your services’s health via the Consul API “/health” endpoint: