Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

service discovery in docker without using consul

I'm new to docker and microservices. I've started to decompose my web-app into microservices and currently, I'm doing manual configuration.

After some study, I came across docker swarm mode which allows service discovery. Also, I came across other tools for service discovery such as Eureka and Consul.

My main aim is to replace IP addresses in curl call with service name and load balance between multiple instances of same service.

i.e. for ex. curl http://192.168.0.11:8080/ to curl http://my-service

I have to keep my services language independent.

Please suggest, Do I need to use Consul with docker swarm for service discovery or i can do it without Consul? What are the advantages?

like image 582
prranay Avatar asked Feb 05 '17 15:02

prranay


2 Answers

With the new "swarm mode", you can use docker services to create clustered services across multiple swarm nodes. You can then access those same services, load-balanced, by using the service name rather than the node name in your requests.

This only applies to nodes within the swarm's overlay network. If your client systems are part of the same swarm, then discovery should work out-of-the-box with no need for any external solutions.

On the other hand, if you want to be able to discover the services from systems outside the swarm, you have a few options:

  • For stateless services, you could use docker's routing mesh, which will make the service port available across all swarm nodes. That way you can just point at any node in the swarm, and docker will direct your request to a node that is running the service (regardless of whether the node you hit has the service or not).
  • Use an actual load balancer in front of your swarm services if you need to control routing or deal with different states. This could either be another docker service (i.e. haproxy, nginx) launched with the --mode global option to ensure it runs on all nodes, or a separate load-balancer like a citrix netscaler. You would need to have your service containers reconfigure the LB through their startup scripts or via provisioning tools (or add them manually).
  • Use something like consul for external service discovery. Possibly in conjunction with registrator to add services automatically. In this scenario you just configure your external clients to use the consul server/cluster for DNS resolution (or use the API).

You could of course just move your service consumers into the swarm as well. If you're separating the clients from the services in different physical VLANs (or VPCs etc) though, you would need to launch your client containers in separate overlay networks to ensure you don't effectively defeat any physical network segregation already in place.

like image 113
Jon Avatar answered Sep 19 '22 16:09

Jon


Service discovery (via dns) is built into docker since version 1.12. When you create a custom network (like bridge or overlay if you have multiple hosts) you can simply have the containers talk to each other via name as long as they are part of same network. You can also have an alias for each container which would round-robin the list of containers which have the same alias. For simple example see:

https://linuxctl.com/docker-networking-options-bridge

like image 29
gbolo Avatar answered Sep 19 '22 16:09

gbolo