networking - 网络和负载均衡器如何在 docker swarm 模式下工作?

标签 networking docker load-balancing docker-swarm-mode

我是 Docker 和容器的新手。我正在阅读 docker 的教程并遇到了这些信息。 https://docs.docker.com/get-started/part3/#docker-composeyml

   networks:
     - webnet
networks:
  webnet:

什么是网络?文件说

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.)

那么,默认情况下,覆盖网络在 docker 集群中是负载均衡的?使用什么负载平衡算法?

实际上,我不清楚为什么我们要在覆盖网络上进行负载平衡。

最佳答案

不确定我是否比文档更清楚,但也许改写会有所帮助。

首先,您在此处关注的文档使用了所谓的 swarm mode docker 。

什么是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.

来自 SO 文档:

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.

因此,在集群模式下,您拥有一个多主机(虚拟机和/或物理)集群,这些机器通过它们的 docker engine 相互通信。 .

第一季度。什么是网络?

webnetoverlay network 的名称它是在您的堆栈启动时创建的。

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

在您的机器集群中,创建了一个虚拟网络,其中每个服务都有一个 ip - 映射到一个内部 DNS 条目(即服务名称),并允许 docker 将传入的数据包路由到正确的容器,无处不在群(集群)。

第二季度。那么,默认情况下,覆盖网络在 docker 集群中是负载均衡的?

是的,如果您使用覆盖网络,但您也可以删除服务 networks 配置以绕过它。那么你将不得不 publish您要公开的服务的端口。

第三季度。使用了什么负载均衡算法?

从此SO question由群主回答 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.

第四季度。实际上我不清楚为什么我们要在覆盖网络上进行负载平衡

docker swarm 模式/服务的目的是允许编排复制的服务,这意味着我们可以扩大/缩小部署在 swarm 中的容器。

来自 docs再次:

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.

因此,您可以部署 10 个完全相同的容器(假设 nginx 与您的应用程序 html/js),而无需处理私有(private)网络 DNS 条目、端口配置等...任何传入请求都将自动负载平衡到主机参与群。

希望这会有所帮助!

关于networking - 网络和负载均衡器如何在 docker swarm 模式下工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44647924/

相关文章:

docker - Nginx:docker 堆栈中的 502 错误网关

nginx - 使用 nginx 开源的粘性 session 负载均衡器

docker - 集群Docker Swarm主机

使用线程的并发 TCP 服务器

docker - 在 docker 中的容器之间共享数据库的最佳实践是什么?

mongodb - 为什么使用docker compose运行MongoDB时更新请求非常慢?

node.js - AWS ELB -> nginx -> socket.io node.js 粘性负载均衡

c - 如何连续发送和接收数据包?

c - MPI——在多台计算机上执行程序

java - 在 Android 上使用 jmDNS 发现网络上的所有服务