1. # Kubernetes CNI Flannel GuideLine
  2. # 时间:20210728-[20:00-22:00]
  3. # 主题:Flannel VxLAN Mode跨节点通信原理解析
  4. # 文档:https://www.yuque.com/docs/share/b03c3c5d-3cc4-42c2-94c4-7be349c9605c?# 《20210725-Flannel VxLAN Mode(二)》
  5. # 作业:VxLAN Mode通信原理

1.Flannel VxLAN Mode跨节点通信原理解析[ENV]

  1. # env:
  2. [root@k8s-1 ~]# kubectl get pods -o wide
  3. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  4. cni-m9l94 1/1 Running 1 121d 10.244.1.5 k8s-2 <none> <none>
  5. cni-w4q8t 1/1 Running 1 121d 10.244.0.3 k8s-1 <none> <none>
  6. [root@k8s-1 ~]#
  7. #1.1: 两Pod的ip和mac信息:
  8. [root@k8s-1 ~]# kubectl exec -it cni-w4q8t -- ifconfig
  9. eth0 Link encap:Ethernet HWaddr CA:3A:FF:17:37:15
  10. inet addr:10.244.0.3 Bcast:10.244.0.255 Mask:255.255.255.0
  11. UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1
  12. RX packets:13 errors:0 dropped:0 overruns:0 frame:0
  13. TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
  14. collisions:0 txqueuelen:0
  15. RX bytes:1178 (1.1 KiB) TX bytes:42 (42.0 B)
  16. lo Link encap:Local Loopback
  17. inet addr:127.0.0.1 Mask:255.0.0.0
  18. UP LOOPBACK RUNNING MTU:65536 Metric:1
  19. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  20. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  21. collisions:0 txqueuelen:1000
  22. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
  23. [root@k8s-1 ~]#
  24. [root@k8s-1 ~]# kubectl exec -it cni-m9l94 -- ifconfig
  25. eth0 Link encap:Ethernet HWaddr A6:73:A0:96:90:71
  26. inet addr:10.244.1.5 Bcast:10.244.1.255 Mask:255.255.255.0
  27. UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1
  28. RX packets:17 errors:0 dropped:0 overruns:0 frame:0
  29. TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
  30. collisions:0 txqueuelen:0
  31. RX bytes:1346 (1.3 KiB) TX bytes:42 (42.0 B)
  32. lo Link encap:Local Loopback
  33. inet addr:127.0.0.1 Mask:255.0.0.0
  34. UP LOOPBACK RUNNING MTU:65536 Metric:1
  35. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  36. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  37. collisions:0 txqueuelen:1000
  38. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
  39. [root@k8s-1 ~]#
  40. #1.2:两节点的ip和mac信息:
  41. # node k8s-1
  42. [root@k8s-1 ~]# ifconfig
  43. cni0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  44. inet 10.244.0.1 netmask 255.255.255.0 broadcast 10.244.0.255
  45. inet6 fe80::4cef:2cff:feeb:43e5 prefixlen 64 scopeid 0x20<link>
  46. ether 4e:ef:2c:eb:43:e5 txqueuelen 1000 (Ethernet)
  47. RX packets 1 bytes 28 (28.0 B)
  48. RX errors 0 dropped 0 overruns 0 frame 0
  49. TX packets 9 bytes 854 (854.0 B)
  50. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  51. docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  52. inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
  53. ether 02:42:bc:2f:2a:a1 txqueuelen 0 (Ethernet)
  54. RX packets 0 bytes 0 (0.0 B)
  55. RX errors 0 dropped 0 overruns 0 frame 0
  56. TX packets 0 bytes 0 (0.0 B)
  57. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  58. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  59. inet 172.12.1.11 netmask 255.255.255.0 broadcast 172.12.1.255
  60. inet6 fe80::e222:32bb:f400:f0c3 prefixlen 64 scopeid 0x20<link>
  61. ether 00:0c:29:bd:fb:4a txqueuelen 1000 (Ethernet)
  62. RX packets 40142 bytes 15743486 (15.0 MiB)
  63. RX errors 0 dropped 0 overruns 0 frame 0
  64. TX packets 38970 bytes 16350462 (15.5 MiB)
  65. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  66. flannel.1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  67. inet 10.244.0.0 netmask 255.255.255.255 broadcast 10.244.0.0
  68. inet6 fe80::485:e5ff:fed3:67f1 prefixlen 64 scopeid 0x20<link>
  69. ether 06:85:e5:d3:67:f1 txqueuelen 0 (Ethernet)
  70. RX packets 0 bytes 0 (0.0 B)
  71. RX errors 0 dropped 0 overruns 0 frame 0
  72. TX packets 0 bytes 0 (0.0 B)
  73. TX errors 0 dropped 20 overruns 0 carrier 0 collisions 0
  74. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  75. inet 127.0.0.1 netmask 255.0.0.0
  76. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  77. loop txqueuelen 1000 (Local Loopback)
  78. RX packets 2660454 bytes 430933651 (410.9 MiB)
  79. RX errors 0 dropped 0 overruns 0 frame 0
  80. TX packets 2660454 bytes 430933651 (410.9 MiB)
  81. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  82. veth56a9232b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  83. inet6 fe80::7871:dff:fe58:4e0b prefixlen 64 scopeid 0x20<link>
  84. ether 7a:71:0d:58:4e:0b txqueuelen 0 (Ethernet)
  85. RX packets 1 bytes 42 (42.0 B)
  86. RX errors 0 dropped 0 overruns 0 frame 0
  87. TX packets 13 bytes 1178 (1.1 KiB)
  88. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  89. # node k8s-2
  90. [root@k8s-2 ~]# ifconfig
  91. cni0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  92. inet 10.244.1.1 netmask 255.255.255.0 broadcast 10.244.1.255
  93. inet6 fe80::dcb6:5cff:fec7:9e0e prefixlen 64 scopeid 0x20<link>
  94. ether de:b6:5c:c7:9e:0e txqueuelen 1000 (Ethernet)
  95. RX packets 39203 bytes 3173480 (3.0 MiB)
  96. RX errors 0 dropped 0 overruns 0 frame 0
  97. TX packets 40749 bytes 3603112 (3.4 MiB)
  98. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  99. docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  100. inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
  101. ether 02:42:58:10:21:7e txqueuelen 0 (Ethernet)
  102. RX packets 0 bytes 0 (0.0 B)
  103. RX errors 0 dropped 0 overruns 0 frame 0
  104. TX packets 0 bytes 0 (0.0 B)
  105. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  106. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  107. inet 172.12.1.12 netmask 255.255.255.0 broadcast 172.12.1.255
  108. inet6 fe80::a9cd:74a4:47fc:9fec prefixlen 64 scopeid 0x20<link>
  109. ether 00:0c:29:e2:bf:86 txqueuelen 1000 (Ethernet)
  110. RX packets 33691 bytes 15290649 (14.5 MiB)
  111. RX errors 0 dropped 0 overruns 0 frame 0
  112. TX packets 27396 bytes 3417296 (3.2 MiB)
  113. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  114. flannel.1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  115. inet 10.244.1.0 netmask 255.255.255.255 broadcast 10.244.1.0
  116. inet6 fe80::e049:6eff:fe06:dd0 prefixlen 64 scopeid 0x20<link>
  117. ether e2:49:6e:06:0d:d0 txqueuelen 0 (Ethernet)
  118. RX packets 0 bytes 0 (0.0 B)
  119. RX errors 0 dropped 0 overruns 0 frame 0
  120. TX packets 0 bytes 0 (0.0 B)
  121. TX errors 0 dropped 20 overruns 0 carrier 0 collisions 0
  122. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  123. inet 127.0.0.1 netmask 255.0.0.0
  124. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  125. loop txqueuelen 1000 (Local Loopback)
  126. RX packets 145 bytes 10896 (10.6 KiB)
  127. RX errors 0 dropped 0 overruns 0 frame 0
  128. TX packets 145 bytes 10896 (10.6 KiB)
  129. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  130. veth41525b19: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  131. inet6 fe80::c0c5:f1ff:fea5:92a7 prefixlen 64 scopeid 0x20<link>
  132. ether c2:c5:f1:a5:92:a7 txqueuelen 0 (Ethernet)
  133. RX packets 19579 bytes 1859591 (1.7 MiB)
  134. RX errors 0 dropped 0 overruns 0 frame 0
  135. TX packets 20383 bytes 1802251 (1.7 MiB)
  136. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  137. veth5cdbe373: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  138. inet6 fe80::fc7b:c4ff:fe59:3814 prefixlen 64 scopeid 0x20<link>
  139. ether fe:7b:c4:59:38:14 txqueuelen 0 (Ethernet)
  140. RX packets 19623 bytes 1862689 (1.7 MiB)
  141. RX errors 0 dropped 0 overruns 0 frame 0
  142. TX packets 20388 bytes 1802573 (1.7 MiB)
  143. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  144. veth756bf3bb: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  145. inet6 fe80::9886:bcff:fead:9d3f prefixlen 64 scopeid 0x20<link>
  146. ether 9a:86:bc:ad:9d:3f txqueuelen 0 (Ethernet)
  147. RX packets 1 bytes 42 (42.0 B)
  148. RX errors 0 dropped 0 overruns 0 frame 0
  149. TX packets 17 bytes 1346 (1.3 KiB)
  150. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2.Flannel VxLAN Mode跨节点通信原理解析-Packet Flow

image.png

  1. #2.1:跨节点通信原理介绍:
  2. [root@k8s-1 ~]# kubectl get pods -o wide
  3. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  4. cni-m9l94 1/1 Running 1 121d 10.244.1.5 k8s-2 <none> <none>
  5. cni-w4q8t 1/1 Running 1 121d 10.244.0.3 k8s-1 <none> <none>
  6. [root@k8s-1 ~]#
  7. #2.2:我们使用k8s-1上的pod cni-w4q8t 去ping k8s-2上的pod cni-m9l94
  8. 对于pod cni-w4q8t 要去的目的地址10.244.1.5 和自己10.244.0.3并不是同一个网段:
  9. 我们需要进行路由查询:
  10. [root@k8s-1 ~]# kubectl exec -it cni-w4q8t -- route -n
  11. Kernel IP routing table
  12. Destination Gateway Genmask Flags Metric Ref Use Iface
  13. 0.0.0.0 10.244.0.1 0.0.0.0 UG 0 0 0 eth0
  14. 10.244.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  15. 10.244.0.0 10.244.0.1 255.255.0.0 UG 0 0 0 eth0 # 此时路由显示去往10.244.0.0/16网络需要发给Gateway:10.244.0.1。
  16. [root@k8s-1 ~]#
  17. 所以需要查询Gateway 10.244.0.1所对应的MAC地址:
  18. No. Time Source Destination Protocol Length Info
  19. #2 2021-07-26 18:14:46.315515 ca:3a:ff:17:37:15 Broadcast ARP 42 Who has 10.244.0.1? Tell 10.244.0.3
  20. Frame 2: 42 bytes on wire (336 bits), 42 bytes captured (336 bits)
  21. Ethernet II, Src: ca:3a:ff:17:37:15 (ca:3a:ff:17:37:15), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
  22. Address Resolution Protocol (request)
  23. No. Time Source Destination Protocol Length Info
  24. #3 2021-07-26 18:14:46.315527 4e:ef:2c:eb:43:e5 ca:3a:ff:17:37:15 ARP 42 10.244.0.1 is at 4e:ef:2c:eb:43:e5 # 此为 k8s-1节点上cni0的mac地址。
  25. Frame 3: 42 bytes on wire (336 bits), 42 bytes captured (336 bits)
  26. Ethernet II, Src: 4e:ef:2c:eb:43:e5 (4e:ef:2c:eb:43:e5), Dst: ca:3a:ff:17:37:15 (ca:3a:ff:17:37:15)
  27. Address Resolution Protocol (reply)
  28. No. Time Source Destination Protocol Length Info
  29. #4 2021-07-26 18:14:46.315529 10.244.0.3 10.244.1.5 ICMP 98 Echo (ping) request id=0x5700, seq=0/0, ttl=64 (reply in 5)
  30. Frame 4: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  31. Ethernet II, Src: ca:3a:ff:17:37:15 (ca:3a:ff:17:37:15), Dst: 4e:ef:2c:eb:43:e5 (4e:ef:2c:eb:43:e5)
  32. Internet Protocol Version 4, Src: 10.244.0.3, Dst: 10.244.1.5
  33. Internet Control Message Protocol
  34. No. Time Source Destination Protocol Length Info
  35. #5 2021-07-26 18:14:46.316067 10.244.1.5 10.244.0.3 ICMP 98 Echo (ping) reply id=0x5700, seq=0/0, ttl=62 (request in 4)
  36. Frame 5: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  37. Ethernet II, Src: 4e:ef:2c:eb:43:e5 (4e:ef:2c:eb:43:e5), Dst: ca:3a:ff:17:37:15 (ca:3a:ff:17:37:15)
  38. Internet Protocol Version 4, Src: 10.244.1.5, Dst: 10.244.0.3
  39. Internet Control Message Protocol
  40. #2.2:此时数据包送到ROOT NS中,那么就开始走ROOT NS的逻辑。查询路由表可得:
  41. <<<<<###需要注意的是:多条路由条目时候,除了网关很重要以外,出接口也非常的重要,因为直接决定从一个接口送出去,就意味着使用哪一个接口的MAC地址。
  42. [root@k8s-1 ~]# route -n
  43. Kernel IP routing table
  44. Destination Gateway Genmask Flags Metric Ref Use Iface
  45. 0.0.0.0 172.12.1.2 0.0.0.0 UG 100 0 0 ens33
  46. 10.244.0.0 0.0.0.0 255.255.255.0 U 0 0 0 cni0
  47. 10.244.1.0 10.244.1.0 255.255.255.0 UG 0 0 0 flannel.1 # 此条络由条目被匹配到,且需要走三层路由转发,且网关为10.244.1.0该地址,而此地址为k8s-2上的flannel.1网卡地址
  48. 172.12.1.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
  49. 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
  50. [root@k8s-1 ~]#
  51. 由上述路由信息,我们可以得到两条重要信息:
  52. 1: 网关是10.244.1.0 该地址是k8s-2节点上的flannel.1(VTEP)的地址。
  53. 2. 数据的出接口为flannel.1。也就是说数据包要从此接口发出。
  54. 这里的转发:需要查询到地址10.244.1.0对应的MAC地址。
  55. ####################
  56. 根据路由表信息我们知道了目的VTEP设备的IP地址,而根据三层IP地址查询二层MAC地址正是ARP表的功能。# 而这里用ARP表的记录,也就是flanneld进程在k8s-2节点启动时,自动添加到k8s-1上的.所以此时ARP的缓存就自动在k8s-1的节点上缓存下来了,也就意味着此时k8s-1不再需要查询ARP了。
  57. ####################
  58. 所以此时的数据报文形式为:
  59. S_IP: 10.244.0.3 S_MAC: $k8s-1_flannel.1_MAC # [06:85:e5:d3:67:f1]
  60. D_IP: 10.244.1.5 D_MAC: $k8s-2_flannel.1_MAC # [e2:49:6e:06:0d:d0]
  61. 抓包显示:
  62. No. Time Source Destination Protocol Length Info
  63. 1 2021-07-26 18:14:46.315561 10.244.0.3 10.244.1.5 ICMP 98 Echo (ping) request id=0x5700, seq=0/0, ttl=63 (reply in 2)
  64. Frame 1: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  65. Ethernet II, Src: 06:85:e5:d3:67:f1 (06:85:e5:d3:67:f1), Dst: e2:49:6e:06:0d:d0 (e2:49:6e:06:0d:d0) # VTEP----S_MAC[$k8s-1_flannel.1] 和 D_MAC[$k8s-2_D_MAC_flannel.1]----VTEP
  66. Internet Protocol Version 4, Src: 10.244.0.3, Dst: 10.244.1.5
  67. Internet Control Message Protocol
  68. No. Time Source Destination Protocol Length Info
  69. 2 2021-07-26 18:14:46.316022 10.244.1.5 10.244.0.3 ICMP 98 Echo (ping) reply id=0x5700, seq=0/0, ttl=63 (request in 1)
  70. Frame 2: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  71. Ethernet II, Src: e2:49:6e:06:0d:d0 (e2:49:6e:06:0d:d0), Dst: 06:85:e5:d3:67:f1 (06:85:e5:d3:67:f1)
  72. Internet Protocol Version 4, Src: 10.244.1.5, Dst: 10.244.0.3
  73. Internet Control Message Protocol
  74. #2.3:由于flannel.1在此环境中同时还扮演者VxLAN VTEP的角色,所以需要安装对应的方式去封装VxLAN的数据报文。
  75. 此时涉及到Inner和Outer的IP和MAC信息问题:[此时需要注意的是:此时的封装数据包是在flannel.1这个VTEP设备来指导下做数据报文的封装----非常重要!!!]
  76. 那么对于k8s-1上的这个VTEP flannel.1它现在知道它所在宿主机上的Outer的S_IP和S_MAC。也知道Inner的S_IP和S_MAC 和 D_IP和D_MAC。
  77. 但是唯独不知道的是D_IP。也就是说不知道10.244.1.0这个地址下的flannel.1在哪一个节点上。
  78. # 在Linux内核里面,网桥设备进行转发的依据来自FDB的转发数据库。这个flannel网桥对应的FDB信息,就是flannel进程维护的。
  79. 所以我们查询:
  80. bridge fdb show | grep $10.244.1.0's_MAC
  81. [root@k8s-1 ~]# bridge fdb show | grep e2:49:6e:06:0d:d0
  82. e2:49:6e:06:0d:d0 dev flannel.1 dst 172.12.1.12 self permanent
  83. [root@k8s-1 ~]#
  84. 由fdb转发信息,我们可以得出10.244.1.0此vtep所在node是172.12.1.12
  85. 到此k8s-1上的VTEP flannel.1获得了所有的封装包信息:
  86. # 然后此时外部的IP信息为:S_IP:172.12.1.11 D_IP:172.12.1.12
  87. 所以需要再次查询路由表信息:
  88. [root@k8s-1 ~]# route -n
  89. Kernel IP routing table
  90. Destination Gateway Genmask Flags Metric Ref Use Iface
  91. 0.0.0.0 172.12.1.2 0.0.0.0 UG 100 0 0 ens33
  92. 10.20.1.0 0.0.0.0 255.255.255.0 U 0 0 0 vxlan0
  93. 10.244.0.0 0.0.0.0 255.255.255.0 U 0 0 0 cni0
  94. 10.244.1.0 10.244.1.0 255.255.255.0 UG 0 0 0 flannel.1
  95. 172.12.1.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 # 被该条路由条目匹配到
  96. 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
  97. [root@k8s-1
  98. # 所以包的形式为:
  99. No. Time Source Destination Protocol Length Info
  100. 25 2021-07-26 18:14:46.315583 10.244.0.3 10.244.1.5 ICMP 148 Echo (ping) request id=0x5700, seq=0/0, ttl=63 (reply in 26)
  101. Frame 25: 148 bytes on wire (1184 bits), 148 bytes captured (1184 bits)
  102. Ethernet II, Src: Vmware_bd:fb:4a (00:0c:29:bd:fb:4a), Dst: Vmware_e2:bf:86 (00:0c:29:e2:bf:86) # Outer_MAC
  103. Internet Protocol Version 4, Src: 172.12.1.11, Dst: 172.12.1.12 # Outer_IP
  104. User Datagram Protocol, Src Port: 39422, Dst Port: 8472 # VxLAN Port
  105. Virtual eXtensible Local Area Network
  106. Ethernet II, Src: 06:85:e5:d3:67:f1 (06:85:e5:d3:67:f1), Dst: e2:49:6e:06:0d:d0 (e2:49:6e:06:0d:d0) # Inner_MAC
  107. Internet Protocol Version 4, Src: 10.244.0.3, Dst: 10.244.1.5 # Inner_IP
  108. Internet Control Message Protocol
  109. No. Time Source Destination Protocol Length Info
  110. 26 2021-07-26 18:14:46.316022 10.244.1.5 10.244.0.3 ICMP 148 Echo (ping) reply id=0x5700, seq=0/0, ttl=63 (request in 25)
  111. Frame 26: 148 bytes on wire (1184 bits), 148 bytes captured (1184 bits)
  112. Ethernet II, Src: Vmware_e2:bf:86 (00:0c:29:e2:bf:86), Dst: Vmware_bd:fb:4a (00:0c:29:bd:fb:4a)
  113. Internet Protocol Version 4, Src: 172.12.1.12, Dst: 172.12.1.11
  114. User Datagram Protocol, Src Port: 35493, Dst Port: 8472
  115. Virtual eXtensible Local Area Network
  116. Ethernet II, Src: e2:49:6e:06:0d:d0 (e2:49:6e:06:0d:d0), Dst: 06:85:e5:d3:67:f1 (06:85:e5:d3:67:f1)
  117. Internet Protocol Version 4, Src: 10.244.1.5, Dst: 10.244.0.3
  118. Internet Control Message Protocol
  119. 此时数据包就可转发出本端。
  120. # 相关数据报文可从这里获得:
  121. # https://github.com/BurlyLuo/cni/tree/master/weiluo/flannel-vxlan

3.VxLAN之MAC in UDP

  1. # ECMP
  2. 在多负载均衡的环境中,通常我们有多条链路可供选择,此时就需要使用到基于流的负载分担了。
  3. 基于流的负载分担我们需要使用到5元组:
  4. S_IP
  5. S_PORT
  6. D_IP
  7. D_PORT
  8. Protocol
  9. 在我们环境中如果想要实现基于流的负载分担,我们可以得到:
  10. S_IP,D_IP,Protocol都是固定的。如果没有引入一个UDP头,此时hash出来的结果都是固定的,就无法实现基于流的负载分担了。
  11. 而UDP的Port中虽然目的端口(8472)是固定的,但是S_PORT是随机的,这样hash出来的结果就不一样了,就可以实现基于流的负载分担了。
  12. 而这里之所以没有使用MAC in TCP的原因是:
  13. 由于TCP需要三次握手,所以会使得其效率变得非常的低。

4.Flannel VxLAN Benchmark

  1. ########################################################################################
  2. Flannel VxLAN Backend
  3. ########################################################################################
  4. bash-5.1# iperf -c 10.244.1.8 -u -b 1000M -f M -i 2
  5. ------------------------------------------------------------
  6. Client connecting to 10.244.1.8, UDP port 5001
  7. Sending 1470 byte datagrams, IPG target: 11.22 us (kalman adjust)
  8. UDP buffer size: 0.203 MByte (default)
  9. ------------------------------------------------------------
  10. [ 1] local 10.244.0.4 port 54220 connected with 10.244.1.8 port 5001
  11. [ ID] Interval Transfer Bandwidth
  12. [ 1] 0.00-2.00 sec 78.5 MBytes 39.3 MBytes/sec
  13. [ 1] 2.00-4.00 sec 77.0 MBytes 38.5 MBytes/sec
  14. [ 1] 4.00-6.00 sec 83.4 MBytes 41.7 MBytes/sec
  15. [ 1] 6.00-8.00 sec 77.9 MBytes 38.9 MBytes/sec
  16. [ 1] 8.00-10.00 sec 77.4 MBytes 38.7 MBytes/sec
  17. [ 1] 0.00-10.00 sec 394 MBytes 39.4 MBytes/sec
  18. [ 1] Sent 281187 datagrams
  19. [ 1] Server Report:
  20. [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
  21. [ 1] 0.00-10.00 sec 394 MBytes 39.4 MBytes/sec 0.203 ms 72/281186 (0.026%)
  22. [ 1] 0.00-10.00 sec 688 datagrams received out-of-order
  23. bash-5.1# iperf -c 10.244.1.8 -t 20 -i 2
  24. ------------------------------------------------------------
  25. Client connecting to 10.244.1.8, TCP port 5001
  26. TCP window size: 85.0 KByte (default)
  27. ------------------------------------------------------------
  28. [ 1] local 10.244.0.4 port 43002 connected with 10.244.1.8 port 5001
  29. [ ID] Interval Transfer Bandwidth
  30. [ 1] 0.00-2.00 sec 387 MBytes 1.62 Gbits/sec
  31. [ 1] 2.00-4.00 sec 490 MBytes 2.05 Gbits/sec
  32. [ 1] 4.00-6.00 sec 467 MBytes 1.96 Gbits/sec
  33. [ 1] 6.00-8.00 sec 469 MBytes 1.97 Gbits/sec
  34. [ 1] 8.00-10.00 sec 503 MBytes 2.11 Gbits/sec
  35. [ 1] 10.00-12.00 sec 477 MBytes 2.00 Gbits/sec
  36. [ 1] 12.00-14.00 sec 495 MBytes 2.08 Gbits/sec
  37. [ 1] 14.00-16.00 sec 500 MBytes 2.10 Gbits/sec
  38. [ 1] 16.00-18.00 sec 495 MBytes 2.08 Gbits/sec
  39. [ 1] 18.00-20.00 sec 502 MBytes 2.11 Gbits/sec
  40. [ 1] 0.00-20.00 sec 4.67 GBytes 2.01 Gbits/sec
  41. bash-5.1#