Docker Swarm叠加网络可以使用ICMP协议,但其他协议无法使用

12

我有一个小的1管理员,3工人的集群设置来试验一些东西。它正在运行Swarm编排,并能够从任何堆栈YAML启动服务并通过Ingress网络提供Web应用程序。我没有对docker-ce的默认yum安装进行任何更改。普通安装,未对任何节点进行配置更改。

但是,存在通过其他覆盖网络进行服务间通信的问题。 我创建了一个带有 --attachable 标志的Docker覆盖网络 testnet,并将一个 nginx 容器(名称为:nginx1)连接到 node-1 上,将 netshoot 容器(名称为:netshoot1)链接到 manager-1 上。

然后,我可以从 netshoot1 ping nginx1,反之亦然。我可以在两个节点上使用 tcpdump 观察这些数据包交换。

# tcpdump -vvnn -i any src 10.1.72.70 and dst 10.1.72.71 and port 4789
00:20:39.302561 IP (tos 0x0, ttl 64, id 49791, offset 0, flags [none], proto UDP (17), length 134)
    10.1.72.70.53237 > 10.1.72.71.4789: [udp sum ok] VXLAN, flags [I] (0x08), vni 4101
IP (tos 0x0, ttl 64, id 20598, offset 0, flags [DF], proto ICMP (1), length 84)
    10.0.5.18 > 10.0.5.24: ICMP echo request, id 21429, seq 1, length 64

您可以看到netshoot1(10.0.5.18)ping nginx1(10.0.5.24)- 回显成功。

但是,如果我执行# curl -v nginx1:80,那么整个过程会超时。

使用tcpdump命令,我可以看到数据包离开manager-1节点,但它们从未到达node-1。

00:22:22.809057 IP (tos 0x0, ttl 64, id 42866, offset 0, flags [none], proto UDP (17), length 110)
    10.1.72.70.53764 > 10.1.72.71.4789: [bad udp cksum 0x5b97 -> 0x697d!] VXLAN, flags [I] (0x08), vni 4101
IP (tos 0x0, ttl 64, id 43409, offset 0, flags [DF], proto TCP (6), length 60)
    10.0.5.18.53668 > 10.0.5.24.80: Flags [S], cksum 0x1e58 (incorrect -> 0x2c3e), seq 1616566654, win 28200, options [mss 1410,sack OK,TS val 913132903 ecr 0,nop,wscale 7], length 0

这些是在 vmware 上运行的内部数据中心虚拟机。网络团队表示,由于IP位于同一子网上,网络防火墙不应该阻止或检查它们。

这是 Docker 配置问题吗?还是iptables的问题?

操作系统:RHEL 8

Docker CE版本:20.10.2

containerd 版本:1.4.3

manager-1上的 IPTABLES

Chain INPUT (policy DROP 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1    9819K 2542M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
2        8   317 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 255
3      473 33064 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
4        0     0 DROP       all  --  *      *       127.0.0.0/8          0.0.0.0/0
5      116  6192 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
6     351K   21M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            source IP range 10.1.72.71-10.1.72.73 state NEW multiport dports 2377,7946 
7      435 58400 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            source IP range 10.1.72.71-10.1.72.73 state NEW multiport dports 7946,4789
8    17142 1747K REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy DROP 8 packets, 384 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1    14081   36M DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0
2    14081   36M DOCKER-INGRESS  all  --  *      *       0.0.0.0/0            0.0.0.0/0
3     267K  995M DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/0
4    39782  121M ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
5     1598 95684 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0
6    41470  717M ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0
7        0     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0
8    90279   23M ACCEPT     all  --  *      docker_gwbridge  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
9        5   300 DOCKER     all  --  *      docker_gwbridge  0.0.0.0/0            0.0.0.0/0
10   94041  134M ACCEPT     all  --  docker_gwbridge !docker_gwbridge  0.0.0.0/0            0.0.0.0/0
11       0     0 DROP       all  --  docker_gwbridge docker_gwbridge  0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT 11M packets, 2365M bytes)
num   pkts bytes target     prot opt in     out     source               destination

Chain DOCKER (2 references)
num   pkts bytes target     prot opt in     out     source               destination
1     1598 95684 ACCEPT     tcp  --  !docker0 docker0  0.0.0.0/0            172.17.0.2           tcp dpt:5000

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1    41470  717M DOCKER-ISOLATION-STAGE-2  all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0
2    93853  133M DOCKER-ISOLATION-STAGE-2  all  --  docker_gwbridge !docker_gwbridge  0.0.0.0/0            0.0.0.0/0
3     267K  995M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-USER (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1    1033K 1699M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-INGRESS (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8502
2        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED tcp spt:8502
3     267K  995M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 DROP       all  --  *      docker0  0.0.0.0/0            0.0.0.0/0
2        0     0 DROP       all  --  *      docker_gwbridge  0.0.0.0/0            0.0.0.0/0
3     135K  851M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

在节点1上使用IPTABLES

Chain INPUT (policy DROP 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1    6211K 3343M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
2        7   233 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 255
3      471 32891 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
4        0     0 DROP       all  --  *      *       127.0.0.0/8          0.0.0.0/0
5       84  4504 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22 /* ssh from anywhere */
6    26940 1616K ACCEPT     tcp  --  *      *       10.1.72.70           0.0.0.0/0            state NEW multiport dports 7946 /* docker swarm cluster comm- manager,node2,3 */
7    31624 1897K ACCEPT     tcp  --  *      *       10.1.72.72           0.0.0.0/0            state NEW multiport dports 7946 /* docker swarm cluster comm- manager,node2,3 */
8    30583 1835K ACCEPT     tcp  --  *      *       10.1.72.73           0.0.0.0/0            state NEW multiport dports 7946 /* docker swarm cluster comm- manager,node2,3 */
9      432 58828 ACCEPT     udp  --  *      *       10.1.72.70           0.0.0.0/0            state NEW multiport dports 7946,4789 /* docker swarm cluster comm and overlay netw- manager,node2,3 */
10      10  1523 ACCEPT     udp  --  *      *       10.1.72.72           0.0.0.0/0            state NEW multiport dports 7946,4789 /* docker swarm cluster comm and overlay netw- manager,node2,3 */
11       7  1159 ACCEPT     udp  --  *      *       10.1.72.73           0.0.0.0/0            state NEW multiport dports 7946,4789 /* docker swarm cluster comm and overlay netw- manager,node2,3 */
12   17172 1749K REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy DROP 19921 packets, 1648K bytes)
num   pkts bytes target     prot opt in     out     source               destination
1    23299   22M DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0
2    23299   22M DOCKER-INGRESS  all  --  *      *       0.0.0.0/0            0.0.0.0/0
3     787K 1473M DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/0
4        0     0 ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
5        0     0 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0
6        0     0 ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0
7        0     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0
8     386K  220M ACCEPT     all  --  *      docker_gwbridge  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
9        0     0 DOCKER     all  --  *      docker_gwbridge  0.0.0.0/0            0.0.0.0/0
10    402K 1254M ACCEPT     all  --  docker_gwbridge !docker_gwbridge  0.0.0.0/0            0.0.0.0/0
11       0     0 DROP       all  --  docker_gwbridge docker_gwbridge  0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT 8193K packets, 2659M bytes)
num   pkts bytes target     prot opt in     out     source               destination

Chain DOCKER-INGRESS (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8502
2        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED tcp spt:8502
3     787K 1473M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-USER (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1     792K 1474M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER (2 references)
num   pkts bytes target     prot opt in     out     source               destination

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 DOCKER-ISOLATION-STAGE-2  all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0
2     402K 1254M DOCKER-ISOLATION-STAGE-2  all  --  docker_gwbridge !docker_gwbridge  0.0.0.0/0            0.0.0.0/0
3     787K 1473M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 DROP       all  --  *      docker0  0.0.0.0/0            0.0.0.0/0
2        0     0 DROP       all  --  *      docker_gwbridge  0.0.0.0/0            0.0.0.0/0
3     402K 1254M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

curl -v nginx1:80 只能从相同堆栈的容器中运行(不能从主机中运行)。您可以分享 docker-compose.yml 文件吗? - Facty
没有compose文件。我只是从管理器创建了一个叠加网络。然后启动两个连接到该网络的容器。其中一个是nginx容器,另一个只是一个bash(netshoot)。我可以从bash中ping通nginx,所以网络和DNS似乎正常工作。但是我无法使用curl、telnet或nc。 - BKaun
我们仍然面临着这个问题,但是相关的事情似乎是一切都在 RHEL 7 上完美正常运作。RHEL 8 导致了这个问题。 - BKaun
1
抱歉,我没有时间。你能分享一下启动容器所使用的命令吗?另外,(我对IPTABLES不太熟悉),可以尝试使用以下命令:firewall-cmd --list-portsfirewall-cmd --list-servicesfirewall-cmd --list-all-zones - Facty
谢谢。最后问题实际上是网络问题。我已经发布了答案。 - BKaun
4个回答

16

问题确实是出在出站数据包的校验和计算出了问题。由于VMware网络接口检测到校验和出现错误,因此丢弃了这些数据包。

解决方法是禁用校验和卸载。可以使用ethtool来完成:

# ethtool -K <interface> tx off

嗨!谢谢分享答案。我花了一整天的时间进行调试。你是我的救星! - valc
1
我花了一天以上的时间来调试!希望这能解决它... - CivFan
2
我已经在所有节点上执行了 ethtool -K ens160 tx offethtool -K docker0 tx offethtool -K docker_gwbridge tx off,但问题仍然存在:( - Libraco
你最终弄清楚了为什么校验和卸载会导致错误的校验和吗?你的主机上安装的是哪个版本的ESXi? - Kayson
@CivFan 我也是。ethtool -K ens192 tx off 解决了我的问题。 - Saeb Molaee
你让我开心极了!你是怎么看待这种行为的? - undefined

4
我遇到了和你一模一样的问题(我的叠加网络中唯一正常运行的是ping命令,其他的全部都消失了)。在我抓狂多日之后,这个帖子帮助了我,所以我想贡献自己的经验。

我的虚拟机也是在vmware服务器上运行的,操作系统是Ubuntu 22.04。我的解决方案是将网络接口类型从vmxnet3更改为简单的E1000E网卡,结果所有东西都突然间恢复正常了。显然,vmxnet3出了一些怪问题。让我纳闷的是,在更多用户使用vmware服务器并运行Docker集群时,这似乎不是一个大问题,对吧?


非常感谢您的分享。我可以确认我看到了相同的问题,这确实指向了vmxnet3校验和实现(或失败处理)的问题。我曾经花费了数天时间调查这个问题! - fifofonix
1
实际上,自从我写这篇文章以来,我已经获得了更多的信息可以分享。看起来核心问题是vmxnet3和docker swarm覆盖网络都使用相同的TCP端口4789。我收到的迹象表明,解决方案可能是在进行docker swarm init时使用--data-path-port参数更改您使用的端口。我自己还没有时间测试这个方法(所以我仍然在使用E1000E),但值得一试! - Daniel Malmgren
@DanielMalmgren:非常感谢您的分享。我一直在为Docker Swarm连接问题苦苦挣扎,但是没有什么帮助;我正在考虑转向Kubernetes。尝试使用您的建议指定不同的--data-path-port解决了所有问题。我很高兴能继续使用Docker Swarm(因为我喜欢它)。再次感谢!FYI:我正在使用小型托管提供商的KVM虚拟化Ubuntu VMs。 - user1018303

1

我遇到了同样的问题,但是我没有使用“ethtool”,而是使用端点模式并将发布端口设置为主机模式来解决问题。以下是我在compose文件中添加的更改:

1-
ports:
  - target: 2379
    published: 2379
    protocol: tcp
    mode: host
2- 
deploy:
  endpoint_mode: dnsrr
3- adding
hostname: <service_name>

1

如果有人尝试过ethtool -K <iface name> tx off但仍然无法解决问题,可以尝试将覆盖网络的MTU大小更改为低于标准值(1500)。

例如:

docker network create -d overlay --attachable --opt com.docker.network.driver.mtu=1450 my-network

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接