Press "Enter" to skip to content

flannel vxlan封装解析

内容目录

机器概览

节点 ip version flannel
master 192.168.0.11 1.22.7 v0.20.1
node1 192.168.0.12 1.22.7 v0.20.1
node2 192.168.0.13 1.22.7 v0.20.1

pod部署测试

在 master 安装 nginx deployment 在两个节点(node1,node2)上用于报文分析

kubectl create deploy ngx-dep --image=nginx:alpine --replicas=4

在 node1 上监听宿主机网卡 eth0

tcpdump -i eth0 -w eth0-node1

在master 执行 从 node1 nginx pod 上 curl node2 上 nginx pod

kubectl exec -it  ngx-dep-cbf8f96f6-r5blp  -- curl 10.244.2.101

报文分析

在 node1 上ctrl+c 或者报文文件eth0-node1

用 wireshark 打开报文文件 查看 vxlan 报文

(需在编辑-首选项-协议中找到 vxlan,修改其端口为 flannel 的 vxlan 的端口号为 8472

或者在高级里搜索 vxlan )

增加过滤条件ip.host==192.168.0.12 && ip.host==192.168.0.13

可获取到 vxlan 内外层 ip mac 表

src ip src mac dst ip dst mac
外层 192.168.0.12 9e:66:01:47:0d:72 192.168.0.13 0a:d2:1d:9d:dc:f7
内层 10.244.1.178 32:73:d8:d1:e9:78 10.244.2.101 ee:81:17:b0:fd:7b

再看节点node1 192.168.0.12, src mac 中外层对应到宿主机网卡 eth0, 内层对应到虚拟网卡 flannel.1

node2 也是同样的情况,综上外层 ip 是 flannel.1 的 local 地址也就是宿主机 eth0 的地址,mac 地址也是对应的宿主机 eth0 的地址

内层 ip 是两个容器的 ip(10.244.1.178→10.244.2.101),mac地址是两端 flannel.1的地址

上面是从结果结合节点网卡情况进行的倒推,那么实际上容器 eth0 到 cni0 后通过路由规则到 flannel.1进行 vxlan 的封装

[root@node1 ~]#  route -n |grep 10.244.2.0
10.244.2.0      10.244.2.0      255.255.255.0   UG    0      0        0 flannel.1

这个时候我们flannel.1只能获取到以下信息

src ip src mac dst ip dst mac
外层 192.168.0.12 9e:66:01:47:0d:72
内层 10.244.1.178 32:73:d8:d1:e9:78 10.244.2.101

flannel.1作为一个VTEP设备,收到报文后将按照VTEP的配置进行封包。内层 dst mac 地址(对端 flannel.1的 mac)从 arp 获取 ee:81:17:b0:fd:7b

[root@node1 ~]# arp -i flannel.1|grep 10.244.2.0
Address                  HWtype  HWaddress           Flags Mask            Iface
10.244.2.0               ether   ee:81:17:b0:fd:7b   CM                    flannel.1

外层目的 ip 192.168.0.13 从 fdb中获取

[root@node1 ~]# bridge fdb show dev flannel.1|grep ee:81:17:b0:fd:7b
ee:81:17:b0:fd:7b dst 192.168.0.13 self permanent

外层dst mac从 eth0 的 arp表获取 0a:d2:1d:9d:dc:f7

[root@node1 ~]# arp -i eth0 -n|grep 192.168.0.13 
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.0.13             ether   0a:d2:1d:9d:dc:f7   C                     eth0

参考

  1. https://blog.csdn.net/qq_41586875/article/details/126558860
  2. https://blog.csdn.net/u014686399/article/details/126109538
  3. https://zhuanlan.zhihu.com/p/157607451
  4. https://www.cnblogs.com/wipan/p/9220615.html
  5. https://weread.qq.com/web/reader/829328f071a74c6182975cc
发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注