Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do networking and load balancer work in docker swarm mode?

Tags:

I am new to Dockers and containers. I was going through the tutorials for docker and came across this information. https://docs.docker.com/get-started/part3/#docker-composeyml

   networks:      - webnet networks:   webnet: 

What is webnet? The document says

Instruct web’s containers to share port 80 via a load-balanced network called webnet. (Internally, the containers themselves will publish to web’s port 80 at an ephemeral port.)

So, by default, the overlay network is load balanced in docker cluster? What is load balancing algo used?

Actually, it is not clear to me why do we have load balancing on the overlay network.

like image 945
SunilS Avatar asked Jun 20 '17 08:06

SunilS


People also ask

Does Docker swarm do load balancing?

Summary. The Docker Swarm mode allows an easy and fast load balancing setup with minimal configuration. Even though the swarm itself already performs a level of load balancing with the ingress mesh, having an external load balancer makes the setup simple to expand upon.

What type of networking is used between containers in Docker swarm clusters?

The overlay network driver creates a distributed network among multiple Docker daemon hosts. This network sits on top of (overlays) the host-specific networks, allowing containers connected to it (including swarm service containers) to communicate securely when encryption is enabled.

Which Docker network is used by Docker Swarm?

The docker_gwbridge network is created automatically when you initialize or join a swarm. Most users do not need to customize its configuration, but Docker allows you to do so.

How does Docker swarm work?

A Docker Swarm is a group of either physical or virtual machines that are running the Docker application and that have been configured to join together in a cluster. The activities of the cluster are controlled by a swarm manager, and machines that have joined the cluster are referred to as nodes.


1 Answers

Not sure I can be clearer than the docs, but maybe rephrasing will help.

First, the doc you're following here uses what is called the swarm mode of docker.

What is swarm mode?

A swarm is a cluster of Docker engines, or nodes, where you deploy services. The Docker Engine CLI and API include commands to manage swarm nodes (e.g., add or remove nodes), and deploy and orchestrate services across the swarm.

From SO Documentation:

A swarm is a number of Docker Engines (or nodes) that deploy services collectively. Swarm is used to distribute processing across many physical, virtual or cloud machines.

So, with swarm mode you have a multi host (vms and/or physical) cluster a machines that communicate with each other through their docker engine.

Q1. What is webnet?

webnet is the name of an overlay network that is created when your stack is launched.

Overlay networks manage communications among the Docker daemons participating in the swarm

In your cluster of machines, a virtual network is the created, where each service has an ip - mapped to an internal DNS entry (which is service name), and allowing docker to route incoming packets to the right container, everywhere in the swarm (cluster).

Q2. So, by default, overlay network is load balanced in docker cluster ?

Yes, if you use the overlay network, but you could also remove the service networks configuration to bypass that. Then you would have to publish the port of the service you want to expose.

Q3. What is load balancing algo used ?

From this SO question answered by swarm master bmitch ;):

The algorithm is currently round-robin and I've seen no indication that it's pluginable yet. A higher level load balancer would allow swarm nodes to be taken down for maintenance, but any sticky sessions or other routing features will be undone by the round-robin algorithm in swarm mode.

Q4. Actually it is not clear to me why do we have load balancing on overlay network

Purpose of docker swarm mode / services is to allow orchestration of replicated services, meaning that we can scale up / down containers deployed in the swarm.

From the docs again:

Swarm mode has an internal DNS component that automatically assigns each service in the swarm a DNS entry. The swarm manager uses internal load balancing to distribute requests among services within the cluster based upon the DNS name of the service.

So you can have deployed like 10 exact same container (let's say nginx with you app html/js), without dealing with private network DNS entries, port configuration, etc... Any incoming request will be automatically load balanced to hosts participating in the swarm.

Hope this helps!

like image 74
François Maturel Avatar answered Nov 01 '22 14:11

François Maturel