1. # Kubernetes CNI Flannel GuideLine
  2. # 时间:20210728-[20:00-22:00]
  3. # 主题:DIY Flannel VxLAN Mode
  4. # 文档:https://www.yuque.com/docs/share/91261581-b309-4053-9e25-60dcc7801917?# 《20210728-Flannel VxLAN Mode(三)》
  5. # 作业:DIY VxLAN
  1. # FAQ:
  2. 每一个技术出来都有它要解决的问题,VXLAN 也不例外,那么我们先看看 VXLAN 到底要解决哪些问题。
  3. 虚拟化(虚拟机和容器)的兴起使得一个数据中心会有成千上万的机器需要通信,而传统的 VLAN 技术只能支持 4096 个网络上限,已经满足不了不断扩展的数据中心规模
  4. 越来越多的数据中心(尤其是公有云服务)需要提供多租户的功能,不同用户之间需要独立地分配 ip 和 MAC 地址,如何保证这个功能的扩展性和正确性也是一个待解决的问题
  5. 云计算业务对业务灵活性要求很高,虚拟机可能会大规模迁移,并保证网络一直可用,也就是大二层的概念。解决这个问题同时保证二层的广播域不会过分扩大,也是云计算网络的要求
  6. 传统二层+三层的网络在应对这些要求时变得力不从心,虽然很多改进型的技术比如堆叠、SVF、TRILL 等能够增加二层的范围,努力改进经典网络,但是要做到对网络改动小同时保证灵活性高却非常困难。
  7. 为了解决这些问题,有很多方案被提出来,vxlan 就是其中之一。vxlan 是 VMware、Cisco 等一众大型企业共同推出的,目前标准文档在 RFC7348。

1.DIY Flannel VxLAN Mode

image.png
DIY VxLAN ENV

  1. # 1.环境配置VxLAN Tunnel:
  2. [root@k8s-1 ~]# yum -y install bridge-utils
  3. #1.k8s-1节点的配置:
  4. ip link add vxlan_docker type vxlan id 20 remote 172.12.1.12 dstport 4789 dev ens33
  5. ip link set vxlan_docker up
  6. brctl addif docker0 vxlan_docker
  7. #2.k8s-2节点的配置:
  8. ip link add vxlan_docker type vxlan id 20 remote 172.12.1.11 dstport 4789 dev ens33
  9. ip link set vxlan_docker up
  10. brctl addif docker0 vxlan_docker
  11. #配置说明
  12. 第一步:创建接口vxlan0 type为vxlan,vni为20.
  13. 第二部:创建的vxlan0 up起来.
  14. 第三步:使用brctl 添加interface vxlan0 到bridge docker0上,连接docker0和vxlan的接口,这样数据包从docker0上来以后,就可以被vxlan封装了。
  15. # 2.启动相关容器:
  16. # 在k8s-1上创建容器:
  17. docker run --name vxlan-c01 -td burlyluo/nettoolbox //该容器的地址为:172.17.0.2。
  18. # 在k8s-2上创建容器:
  19. docker run --name vxlan-c01 -td burlyluo/nettoolbox //该容器的地址为:172.17.0.2。
  20. docker run --name vxlan-c02 -td burlyluo/nettoolbox //该容器的地址为:172.17.0.3。
  21. # 3.ping测:
  22. [root@k8s-1 ~]# docker exec -it vxlan-c01 bash
  23. bash-5.0# ping 172.17.0.3
  24. PING 172.17.0.3 (172.17.0.3): 56 data bytes
  25. 64 bytes from 172.17.0.3: seq=0 ttl=64 time=1.446 ms
  26. 64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.643 ms
  27. ^C
  28. --- 172.17.0.3 ping statistics ---
  29. 2 packets transmitted, 2 packets received, 0% packet loss
  30. round-trip min/avg/max = 0.643/1.044/1.446 ms
  31. bash-5.0#
  32. #####################
  33. 地址信息:
  34. k8s-1节点:
  35. [root@k8s-1 ~]# ifconfig
  36. [root@k8s-1 ~]# docker exec -it vxlan-c01 ifconfig
  37. eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
  38. inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
  39. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  40. RX packets:19 errors:0 dropped:0 overruns:0 frame:0
  41. TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
  42. collisions:0 txqueuelen:0
  43. RX bytes:1398 (1.3 KiB) TX bytes:182 (182.0 B)
  44. ---#
  45. docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  46. inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
  47. inet6 fe80::42:c9ff:feeb:2769 prefixlen 64 scopeid 0x20<link>
  48. ether 02:42:c9:eb:27:69 txqueuelen 0 (Ethernet)
  49. RX packets 18 bytes 1252 (1.2 KiB)
  50. RX errors 0 dropped 0 overruns 0 frame 0
  51. TX packets 5 bytes 526 (526.0 B)
  52. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  53. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  54. inet 172.12.1.11 netmask 255.255.255.0 broadcast 172.12.1.255
  55. inet6 fe80::e222:32bb:f400:f0c3 prefixlen 64 scopeid 0x20<link>
  56. ether 00:0c:29:bd:fb:4a txqueuelen 1000 (Ethernet)
  57. RX packets 2833 bytes 356496 (348.1 KiB)
  58. RX errors 0 dropped 0 overruns 0 frame 0
  59. TX packets 3103 bytes 1317158 (1.2 MiB)
  60. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  61. vxlan_docker: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  62. inet6 fe80::4431:deff:fe40:88d1 prefixlen 64 scopeid 0x20<link>
  63. ether 46:31:de:40:88:d1 txqueuelen 1000 (Ethernet)
  64. RX packets 20 bytes 1364 (1.3 KiB)
  65. RX errors 0 dropped 0 overruns 0 frame 0
  66. TX packets 20 bytes 1364 (1.3 KiB)
  67. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  68. # k8s-2 节点:
  69. [root@k8s-2 ~]# docker exec -it vxlan-c02 ifconfig
  70. eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:03
  71. inet addr:172.17.0.3 Bcast:172.17.255.255 Mask:255.255.0.0
  72. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  73. RX packets:18 errors:0 dropped:0 overruns:0 frame:0
  74. TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
  75. collisions:0 txqueuelen:0
  76. RX bytes:1328 (1.2 KiB) TX bytes:182 (182.0 B)
  77. ---#
  78. docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  79. inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
  80. inet6 fe80::42:dcff:fea0:192e prefixlen 64 scopeid 0x20<link>
  81. ether 02:42:dc:a0:19:2e txqueuelen 0 (Ethernet)
  82. RX packets 6 bytes 308 (308.0 B)
  83. RX errors 0 dropped 0 overruns 0 frame 0
  84. TX packets 5 bytes 526 (526.0 B)
  85. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  86. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  87. inet 172.12.1.12 netmask 255.255.255.0 broadcast 172.12.1.255
  88. inet6 fe80::a9cd:74a4:47fc:9fec prefixlen 64 scopeid 0x20<link>
  89. ether 00:0c:29:e2:bf:86 txqueuelen 1000 (Ethernet)
  90. RX packets 2620 bytes 1116242 (1.0 MiB)
  91. RX errors 0 dropped 0 overruns 0 frame 0
  92. TX packets 2065 bytes 282698 (276.0 KiB)
  93. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  94. vxlan_docker: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1450
  95. inet6 fe80::d463:d8ff:fee1:8b73 prefixlen 64 scopeid 0x20<link>
  96. ether d6:63:d8:e1:8b:73 txqueuelen 1000 (Ethernet)
  97. RX packets 8 bytes 420 (420.0 B)
  98. RX errors 0 dropped 0 overruns 0 frame 0
  99. TX packets 20 bytes 1364 (1.3 KiB)
  100. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  101. #####################
  102. #4.抓包:
  103. #4.1:从容器到docker0网桥:eth0接口抓包
  104. No. Time Source Destination Protocol Length Info
  105. 1 2021-07-26 20:54:03.857948 02:42:ac:11:00:02 Broadcast ARP 42 Who has 172.17.0.3? Tell 172.17.0.2
  106. Frame 1: 42 bytes on wire (336 bits), 42 bytes captured (336 bits)
  107. Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
  108. Address Resolution Protocol (request)
  109. No. Time Source Destination Protocol Length Info
  110. 2 2021-07-26 20:54:03.858531 02:42:ac:11:00:03 02:42:ac:11:00:02 ARP 42 172.17.0.3 is at 02:42:ac:11:00:03
  111. Frame 2: 42 bytes on wire (336 bits), 42 bytes captured (336 bits)
  112. Ethernet II, Src: 02:42:ac:11:00:03 (02:42:ac:11:00:03), Dst: 02:42:ac:11:00:02 (02:42:ac:11:00:02)
  113. Address Resolution Protocol (reply)
  114. No. Time Source Destination Protocol Length Info
  115. 3 2021-07-26 20:54:03.858537 172.17.0.2 172.17.0.3 ICMP 98 Echo (ping) request id=0x1d00, seq=0/0, ttl=64 (reply in 4)
  116. Frame 3: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  117. Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: 02:42:ac:11:00:03 (02:42:ac:11:00:03)
  118. Internet Protocol Version 4, Src: 172.17.0.2, Dst: 172.17.0.3
  119. Internet Control Message Protocol
  120. No. Time Source Destination Protocol Length Info
  121. 4 2021-07-26 20:54:03.858948 172.17.0.3 172.17.0.2 ICMP 98 Echo (ping) reply id=0x1d00, seq=0/0, ttl=64 (request in 3)
  122. Frame 4: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  123. Ethernet II, Src: 02:42:ac:11:00:03 (02:42:ac:11:00:03), Dst: 02:42:ac:11:00:02 (02:42:ac:11:00:02)
  124. Internet Protocol Version 4, Src: 172.17.0.3, Dst: 172.17.0.2
  125. Internet Control Message Protocol
  126. #4.2:学习对端VTEP的MAC地址:vxlan_docker上抓包
  127. No. Time Source Destination Protocol Length Info
  128. 3 2021-07-26 20:54:03.857965 02:42:ac:11:00:02 Broadcast ARP 42 Who has 172.17.0.3? Tell 172.17.0.2
  129. Frame 3: 42 bytes on wire (336 bits), 42 bytes captured (336 bits)
  130. Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
  131. Address Resolution Protocol (request)
  132. No. Time Source Destination Protocol Length Info
  133. 4 2021-07-26 20:54:03.858469 02:42:ac:11:00:03 02:42:ac:11:00:02 ARP 42 172.17.0.3 is at 02:42:ac:11:00:03
  134. Frame 4: 42 bytes on wire (336 bits), 42 bytes captured (336 bits)
  135. Ethernet II, Src: 02:42:ac:11:00:03 (02:42:ac:11:00:03), Dst: 02:42:ac:11:00:02 (02:42:ac:11:00:02)
  136. Address Resolution Protocol (reply)
  137. No. Time Source Destination Protocol Length Info
  138. 5 2021-07-26 20:54:03.858549 172.17.0.2 172.17.0.3 ICMP 98 Echo (ping) request id=0x1d00, seq=0/0, ttl=64 (reply in 6)
  139. Frame 5: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  140. Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: 02:42:ac:11:00:03 (02:42:ac:11:00:03)
  141. Internet Protocol Version 4, Src: 172.17.0.2, Dst: 172.17.0.3
  142. Internet Control Message Protocol
  143. No. Time Source Destination Protocol Length Info
  144. 6 2021-07-26 20:54:03.858915 172.17.0.3 172.17.0.2 ICMP 98 Echo (ping) reply id=0x1d00, seq=0/0, ttl=64 (request in 5)
  145. Frame 6: 98 bytes on wire (784 bits), 98 bytes captured (784 bits)
  146. Ethernet II, Src: 02:42:ac:11:00:03 (02:42:ac:11:00:03), Dst: 02:42:ac:11:00:02 (02:42:ac:11:00:02)
  147. Internet Protocol Version 4, Src: 172.17.0.3, Dst: 172.17.0.2
  148. Internet Control Message Protocol
  149. #4.3:构造VxLAN数据报文:
  150. No. Time Source Destination Protocol Length Info
  151. 683 2021-07-26 20:54:03.857992 02:42:ac:11:00:02 Broadcast ARP 92 Who has 172.17.0.3? Tell 172.17.0.2
  152. Frame 683: 92 bytes on wire (736 bits), 92 bytes captured (736 bits)
  153. Ethernet II, Src: Vmware_bd:fb:4a (00:0c:29:bd:fb:4a), Dst: Vmware_e2:bf:86 (00:0c:29:e2:bf:86)
  154. Internet Protocol Version 4, Src: 172.12.1.11, Dst: 172.12.1.12
  155. User Datagram Protocol, Src Port: 51305, Dst Port: 4789
  156. Virtual eXtensible Local Area Network
  157. Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
  158. Address Resolution Protocol (request)
  159. No. Time Source Destination Protocol Length Info
  160. 684 2021-07-26 20:54:03.858469 02:42:ac:11:00:03 02:42:ac:11:00:02 ARP 92 172.17.0.3 is at 02:42:ac:11:00:03
  161. Frame 684: 92 bytes on wire (736 bits), 92 bytes captured (736 bits)
  162. Ethernet II, Src: Vmware_e2:bf:86 (00:0c:29:e2:bf:86), Dst: Vmware_bd:fb:4a (00:0c:29:bd:fb:4a)
  163. Internet Protocol Version 4, Src: 172.12.1.12, Dst: 172.12.1.11
  164. User Datagram Protocol, Src Port: 51881, Dst Port: 4789
  165. Virtual eXtensible Local Area Network
  166. Ethernet II, Src: 02:42:ac:11:00:03 (02:42:ac:11:00:03), Dst: 02:42:ac:11:00:02 (02:42:ac:11:00:02)
  167. Address Resolution Protocol (reply)
  168. No. Time Source Destination Protocol Length Info
  169. 685 2021-07-26 20:54:03.858562 172.17.0.2 172.17.0.3 ICMP 148 Echo (ping) request id=0x1d00, seq=0/0, ttl=64 (reply in 688)
  170. Frame 685: 148 bytes on wire (1184 bits), 148 bytes captured (1184 bits)
  171. Ethernet II, Src: Vmware_bd:fb:4a (00:0c:29:bd:fb:4a), Dst: Vmware_e2:bf:86 (00:0c:29:e2:bf:86)
  172. Internet Protocol Version 4, Src: 172.12.1.11, Dst: 172.12.1.12
  173. User Datagram Protocol, Src Port: 45497, Dst Port: 4789
  174. Virtual eXtensible Local Area Network
  175. Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: 02:42:ac:11:00:03 (02:42:ac:11:00:03)
  176. Internet Protocol Version 4, Src: 172.17.0.2, Dst: 172.17.0.3
  177. Internet Control Message Protocol
  178. No. Time Source Destination Protocol Length Info
  179. 688 2021-07-26 20:54:03.858915 172.17.0.3 172.17.0.2 ICMP 148 Echo (ping) reply id=0x1d00, seq=0/0, ttl=64 (request in 685)
  180. Frame 688: 148 bytes on wire (1184 bits), 148 bytes captured (1184 bits)
  181. Ethernet II, Src: Vmware_e2:bf:86 (00:0c:29:e2:bf:86), Dst: Vmware_bd:fb:4a (00:0c:29:bd:fb:4a)
  182. Internet Protocol Version 4, Src: 172.12.1.12, Dst: 172.12.1.11
  183. User Datagram Protocol, Src Port: 59330, Dst Port: 4789
  184. Virtual eXtensible Local Area Network
  185. Ethernet II, Src: 02:42:ac:11:00:03 (02:42:ac:11:00:03), Dst: 02:42:ac:11:00:02 (02:42:ac:11:00:02)
  186. Internet Protocol Version 4, Src: 172.17.0.3, Dst: 172.17.0.2
  187. Internet Control Message Protocol
  188. # 抓包可从这里获取:
  189. # https://github.com/BurlyLuo/cni/tree/master/weiluo/diy-vxlan