user62058
user62058

Reputation: 1527

consul: how many agents for services

I am playing a little with Docker and Consul and i have a couple of questions regarding agent-service mapping especially in docker environment. Assume i have a service name "myGreatService" being simple web nodejs helloworld application encapsulated with docker image named "myGreatServiceImage". From Consul docs i did understand that when you register a service (through HTTP or service definition file) than service is about to be "wired" to agent/consul node (the wired node can be retrieved via /v1/catalog/service/). So if a consul node is down (or node health check decided it is down) than all services "wired" to that consule node will automatically be marked as down. Am i right ?

If i run my GreatServiceImage image multiple times on a single host via docker (resulting of multiple instances of "myGreatService" service) how many agents shall I run ? A single per host managing all containers (all service instances) on that host? Or maybe a separate agent for each container (service instance) ?

Upvotes: 2

Views: 2064

Answers (1)

Brrrr
Brrrr

Reputation: 4598

If a health check for a service fails then the service will be marked as down and won't show up if you do a DNS query for that service

dig @localhost -p 8500 apache.service.consul

If you do a call to the api you will see that the service is still listed. This is because the service is not removed, it is just marked as down. If you would do an api call to check the health of that service it would be shown as down.

curl localhost/v1/catalog/service/apache
curl localhost/v1/health/service/apache 

You can add the ?passing flag to that last call to recieve only the healthy services. (just like the dns query)

curl localhost/v1/health/service/apache?passing

If the consul agent on the host fails then all services running on that host won't show up if you query consul for the services. (either via a dns query or via the api).

As for the number of agents you should be running: Run one consul agent per host. Let your services register themselves via the api of your local consul agent. (or preconfigure all your services in the config files, but I recommend you to make this a dynamic process of self registering)

Upvotes: 6

Related Questions