Opening a service in docker without using a consul

I am new to dockers and microservices. I started decomposing my web application into microservices, and I am currently doing manual configuration.

After some research, I came across a docker roaming mode that allows you to discover services. In addition, I came across other service discovery tools such as Eureka and Consul.

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

i.e. e.g. curl http://192.168.0.11:8080/ for curling http: // my-service

I must maintain the independence of my services.

Please suggest if I need to use the Consul with a docker rome to discover the service, or can I do this without the Consul? What are the benefits?

+5
source share
3 answers

With the new โ€œswarm modeโ€, you can use docker services to create clustered services in multiple swarm nodes. You can then access the same load-balanced services using the service name, not the node name in your requests.

This only applies to swarm overlay network nodes. If your client systems are part of the same swarm, then the discovery should work without any external solutions.

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

  • For stateless services, you can use the docker routing grid , which will make the service port available to all swarm nodes. That way, you can simply point to any node in the swarm, and the docker will direct your request to the node that starts the service (regardless of whether your node has a service or not).
  • Use the actual load balancer in front of your swarm services if you need to control routing or deal with different states. It can be either another docker service (i.e. Haproxy, nginx) launched with the --mode global option to ensure that it works on all nodes, or a separate load balancer, such as citrix netscaler. You will need your service containers to reconfigure LB through their startup scripts or through provisioning tools (or add them manually).
  • Use something like a consul to discover external services. Perhaps in conjunction with registrator to automatically add services. In this scenario, you simply configure external clients to use the consul server / cluster to resolve DNS (or use the API).

Of course, you can simply move your service consumers to a swarm. If you separate clients from services in different physical VLANs (or VPCs, etc.), you will need to run client containers on separate overlay networks to ensure that you cannot effectively destroy any physical network segregation already in place.

+5
source

Service discovery (via dns) has been built into docker since version 1.12. When you create a custom network (for example, a bridge or overlay if you have multiple hosts), you can simply use the containers with each other by name if they are part of the same network. You can also have an alias for each container that will list the containers that have the same alias. For a simple example, see:

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

0
source

As long as you use the bridge mode for your docker network and create your containers within this network, service discovery is available to you out of the box.

You will need to get help from other tools as soon as your infrastructure begins to cover several servers and microservices distributed on them.

Roy is a good tool to start with, but I would like to stick with the consul when it comes to any IaaS vendor, such as Amazon, for my workloads.

0
source

Source: https://habr.com/ru/post/1263843/


All Articles