为什么 flannel 的 host-gw 需要主机之间的直接 layer2 连接?
why host-gw of flannel requires direct layer2 connectivity between hosts?
由于 host-gw 通过远程机器 IP 使用到子网的 IP 路由,它看起来像是纯 L3 网络解决方案。
因此,为什么主机之间需要直接 L2 连接?
host-gw
在主机上添加路由 table 条目,以便主机知道如何传输容器网络数据包。
这适用于 L2,因为它只涉及 hosts
、switches
和 containers
。 switches
不关心 IP 和路由,hosts
知道 containers
存在,以及如何路由到它们,containers
只是发送和接收数据。
如果hosts
在不同的网络,引入L3,涉及routers
。 routers
不知道 containers
存在,任何容器数据包都将被丢弃,使通信无法进行。
当然,您可以在 routers
上添加路由 table 条目,但这是无法控制的 flannel
。
host-gw 在每个主机上添加路由 table 整体。条目如下:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.110.110.1 0.0.0.0 UG 100 0 0 eth0
10.100.14.0 10.110.110.21 255.255.255.0 UG 0 0 0 eth0
10.100.38.0 0.0.0.0 255.255.255.0 U 0 0 0 docker0
10.110.110.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
169.254.169.254 10.110.110.1 255.255.255.255 UGH 100 0 0 eth0
最重要的项目是网关(10.110.110.21)的值。路由 table 会将目标 mac 地址更改为节点 (10.110.110.21) 的 mac_address,该节点将 L2 直接连接到 10.110.110.22(当前节点)。
如果没有 L2 连接,则数据包无法传递到节点(下一跳)
由于 host-gw 通过远程机器 IP 使用到子网的 IP 路由,它看起来像是纯 L3 网络解决方案。
因此,为什么主机之间需要直接 L2 连接?
host-gw
在主机上添加路由 table 条目,以便主机知道如何传输容器网络数据包。
这适用于 L2,因为它只涉及 hosts
、switches
和 containers
。 switches
不关心 IP 和路由,hosts
知道 containers
存在,以及如何路由到它们,containers
只是发送和接收数据。
如果hosts
在不同的网络,引入L3,涉及routers
。 routers
不知道 containers
存在,任何容器数据包都将被丢弃,使通信无法进行。
当然,您可以在 routers
上添加路由 table 条目,但这是无法控制的 flannel
。
host-gw 在每个主机上添加路由 table 整体。条目如下:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.110.110.1 0.0.0.0 UG 100 0 0 eth0
10.100.14.0 10.110.110.21 255.255.255.0 UG 0 0 0 eth0
10.100.38.0 0.0.0.0 255.255.255.0 U 0 0 0 docker0
10.110.110.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
169.254.169.254 10.110.110.1 255.255.255.255 UGH 100 0 0 eth0
最重要的项目是网关(10.110.110.21)的值。路由 table 会将目标 mac 地址更改为节点 (10.110.110.21) 的 mac_address,该节点将 L2 直接连接到 10.110.110.22(当前节点)。
如果没有 L2 连接,则数据包无法传递到节点(下一跳)