1. # Kubernetes CNI IPVLAN
  2. # 时间:20210822-[14:00-17:00]
  3. # 主题:IPVLAN
  4. # 文档:https://www.yuque.com/docs/share/a41344f8-79fa-499b-98b7-de94b6d5c4ba?# 《20210815-IPVLAN L2 Mode》
  5. # 作业:IPVLAN L2
  1. # FAQ:

IPVLAN

  1. IPVLAN:
  2. IPVLAN Driver HOWTO
  3. Initial Release:
  4. Mahesh Bandewar <maheshb AT google.com>
  5. 1. Introduction:
  6. This is conceptually very similar to the macvlan driver with one major
  7. exception of using L3 for mux-ing /demux-ing among slaves. This property makes
  8. the master device share the L2 with it's slave devices. I have developed this
  9. driver in conjunction with network namespaces and not sure if there is use case
  10. outside of it.
  11. 2. Building and Installation:
  12. In order to build the driver, please select the config item CONFIG_IPVLAN.
  13. The driver can be built into the kernel (CONFIG_IPVLAN=y) or as a module
  14. (CONFIG_IPVLAN=m).
  15. 3. Configuration:
  16. There are no module parameters for this driver and it can be configured
  17. using IProute2/ip utility.
  18. ip link add link <master> name <slave> type ipvlan [ mode MODE ] [ FLAGS ]
  19. where
  20. MODE: l3 (default) | l3s | l2
  21. FLAGS: bridge (default) | private | vepa
  22. e.g.
  23. (a) Following will create IPvlan link with eth0 as master in
  24. L3 bridge mode
  25. bash# ip link add link eth0 name ipvl0 type ipvlan
  26. (b) This command will create IPvlan link in L2 bridge mode.
  27. bash# ip link add link eth0 name ipvl0 type ipvlan mode l2 bridge
  28. (c) This command will create an IPvlan device in L2 private mode.
  29. bash# ip link add link eth0 name ipvlan type ipvlan mode l2 private
  30. (d) This command will create an IPvlan device in L2 vepa mode.
  31. bash# ip link add link eth0 name ipvlan type ipvlan mode l2 vepa
  32. 4. Operating modes:
  33. IPvlan has two modes of operation - L2 and L3. For a given master device,
  34. you can select one of these two modes and all slaves on that master will
  35. operate in the same (selected) mode. The RX mode is almost identical except
  36. that in L3 mode the slaves wont receive any multicast / broadcast traffic.
  37. L3 mode is more restrictive since routing is controlled from the other (mostly)
  38. default namespace.
  39. 4.1 L2 mode:
  40. In this mode TX processing happens on the stack instance attached to the
  41. slave device and packets are switched and queued to the master device to send
  42. out. In this mode the slaves will RX/TX multicast and broadcast (if applicable)
  43. as well.
  44. 4.2 L3 mode:
  45. In this mode TX processing up to L3 happens on the stack instance attached
  46. to the slave device and packets are switched to the stack instance of the
  47. master device for the L2 processing and routing from that instance will be
  48. used before packets are queued on the outbound device. In this mode the slaves
  49. will not receive nor can send multicast / broadcast traffic.
  50. 4.3 L3S mode:
  51. This is very similar to the L3 mode except that iptables (conn-tracking)
  52. works in this mode and hence it is L3-symmetric (L3s). This will have slightly less
  53. performance but that shouldn't matter since you are choosing this mode over plain-L3
  54. mode to make conn-tracking work.
  55. 5. Mode flags:
  56. At this time following mode flags are available
  57. 5.1 bridge:
  58. This is the default option. To configure the IPvlan port in this mode,
  59. user can choose to either add this option on the command-line or don't specify
  60. anything. This is the traditional mode where slaves can cross-talk among
  61. themselves apart from talking through the master device.
  62. 5.2 private:
  63. If this option is added to the command-line, the port is set in private
  64. mode. i.e. port won't allow cross communication between slaves.
  65. 5.3 vepa:
  66. If this is added to the command-line, the port is set in VEPA mode.
  67. i.e. port will offload switching functionality to the external entity as
  68. described in 802.1Qbg
  69. Note: VEPA mode in IPvlan has limitations. IPvlan uses the mac-address of the
  70. master-device, so the packets which are emitted in this mode for the adjacent
  71. neighbor will have source and destination mac same. This will make the switch /
  72. router send the redirect message.
  73. 6. What to choose (macvlan vs. ipvlan)?
  74. These two devices are very similar in many regards and the specific use
  75. case could very well define which device to choose. if one of the following
  76. situations defines your use case then you can choose to use ipvlan -
  77. (a) The Linux host that is connected to the external switch / router has
  78. policy configured that allows only one mac per port.
  79. (b) No of virtual devices created on a master exceed the mac capacity and
  80. puts the NIC in promiscuous mode and degraded performance is a concern.
  81. (c) If the slave device is to be put into the hostile / untrusted network
  82. namespace where L2 on the slave could be changed / misused.
  83. 6. Example configuration:
  84. +=============================================================+
  85. | Host: host1 |
  86. | |
  87. | +----------------------+ +----------------------+ |
  88. | | NS:ns0 | | NS:ns1 | |
  89. | | | | | |
  90. | | | | | |
  91. | | ipvl0 | | ipvl1 | |
  92. | +----------#-----------+ +-----------#----------+ |
  93. | # # |
  94. | ################################ |
  95. | # eth0 |
  96. +==============================#==============================+
  97. (a) Create two network namespaces - ns0, ns1
  98. ip netns add ns0
  99. ip netns add ns1
  100. (b) Create two ipvlan slaves on eth0 (master device)
  101. ip link add link eth0 ipvl0 type ipvlan mode l2
  102. ip link add link eth0 ipvl1 type ipvlan mode l2
  103. (c) Assign slaves to the respective network namespaces
  104. ip link set dev ipvl0 netns ns0
  105. ip link set dev ipvl1 netns ns1
  106. (d) Now switch to the namespace (ns0 or ns1) to configure the slave devices
  107. - For ns0
  108. (1) ip netns exec ns0 bash
  109. (2) ip link set dev ipvl0 up
  110. (3) ip link set dev lo up
  111. (4) ip -4 addr add 127.0.0.1 dev lo
  112. (5) ip -4 addr add $IPADDR dev ipvl0
  113. (6) ip -4 route add default via $ROUTER dev ipvl0
  114. - For ns1
  115. (1) ip netns exec ns1 bash
  116. (2) ip link set dev ipvl1 up
  117. (3) ip link set dev lo up
  118. (4) ip -4 addr add 127.0.0.1 dev lo
  119. (5) ip -4 addr add $IPADDR dev ipvl1
  120. (6) ip -4 route add default via $ROUTER dev ipvl1

IPVLAN L2

  1. L2 模式
  2. 在 IPVLAN L2 模式 中,虚拟设备接收并响应地址解析协议(ARP)请求。netfilter 框架仅在拥有虚拟设备的容器中运行。容器化流量的默认命名空间中没有执行 netfilter 链。使用L2 模式会提供良好的性能,但对网络流量的控制要小。

20210822-IPVLAN L2&L3 Mode - 图1

  1. # IPVLAN L2:
  2. # 1.Add ns:
  3. ip netns add net1
  4. ip netns add net2
  5. # 2. Set the ipvlan l2 mode:
  6. ip link add ipvlan1 link ens33 type ipvlan mode l2
  7. ip link add ipvlan2 link ens33 type ipvlan mode l2
  8. # 3.Add the interface to ns:
  9. ip link set ipvlan1 netns net1
  10. ip link set ipvlan2 netns net2
  11. # 4. config ip address:
  12. ip netns exec net1 ifconfig ipvlan1 172.12.1.5/24 up
  13. ip netns exec net2 ifconfig ipvlan2 172.12.1.6/24 up
  14. # outputs:
  15. [root@k8s-1 ~]# ip netns exec net1 ping 172.12.1.6
  16. PING 172.12.1.6 (172.12.1.6) 56(84) bytes of data.
  17. 64 bytes from 172.12.1.6: icmp_seq=1 ttl=64 time=0.133 ms
  18. 64 bytes from 172.12.1.6: icmp_seq=2 ttl=64 time=0.044 ms
  19. ^C
  20. --- 172.12.1.6 ping statistics ---
  21. 2 packets transmitted, 2 received, 0% packet loss, time 1004ms
  22. rtt min/avg/max/mdev = 0.044/0.088/0.133/0.045 ms
  23. [root@k8s-1 ~]#
  24. # MAC Address:
  25. [root@k8s-1 ~]# ip netns exec net1 ifconfig
  26. ipvlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  27. inet 172.12.1.5 netmask 255.255.255.0 broadcast 172.12.1.255
  28. inet6 fe80::c:2900:1bd:fb4a prefixlen 64 scopeid 0x20<link>
  29. ether 00:0c:29:bd:fb:4a txqueuelen 1000 (Ethernet) # mac address: 00:0c:29:bd:fb:4a
  30. RX packets 15 bytes 1108 (1.0 KiB)
  31. RX errors 0 dropped 0 overruns 0 frame 0
  32. TX packets 17 bytes 1342 (1.3 KiB)
  33. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  34. [root@k8s-1 ~]# ip netns exec net2 ifconfig
  35. ipvlan2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  36. inet 172.12.1.6 netmask 255.255.255.0 broadcast 172.12.1.255
  37. inet6 fe80::c:2900:2bd:fb4a prefixlen 64 scopeid 0x20<link>
  38. ether 00:0c:29:bd:fb:4a txqueuelen 1000 (Ethernet) # mac address: 00:0c:29:bd:fb:4a
  39. RX packets 11 bytes 936 (936.0 B)
  40. RX errors 0 dropped 0 overruns 0 frame 0
  41. TX packets 28 bytes 1916 (1.8 KiB)
  42. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  43. [root@k8s-1 ~]# ifconfig ens33
  44. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  45. inet 172.12.1.11 netmask 255.255.255.0 broadcast 172.12.1.255
  46. inet6 fe80::e222:32bb:f400:f0c3 prefixlen 64 scopeid 0x20<link>
  47. ether 00:0c:29:bd:fb:4a txqueuelen 1000 (Ethernet) # mac address: 00:0c:29:bd:fb:4a
  48. RX packets 777393 bytes 104721748 (99.8 MiB)
  49. RX errors 0 dropped 0 overruns 0 frame 0
  50. TX packets 962628 bytes 447851355 (427.1 MiB)
  51. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  52. [root@k8s-1 ~]#
  53. [root@k8s-1 ~]# ip netns exec net1 arp -n
  54. [root@k8s-1 ~]# ip netns exec net1 ping 172.12.1.6
  55. PING 172.12.1.6 (172.12.1.6) 56(84) bytes of data.
  56. 64 bytes from 172.12.1.6: icmp_seq=1 ttl=64 time=0.094 ms
  57. ^C
  58. --- 172.12.1.6 ping statistics ---
  59. 1 packets transmitted, 1 received, 0% packet loss, time 0ms
  60. rtt min/avg/max/mdev = 0.094/0.094/0.094/0.000 ms
  61. [root@k8s-1 ~]#
  62. # capture on interface ipvaln1
  63. [root@k8s-1 ~]# ip netns exec net1 tcpdump -ne -i ipvlan1
  64. 20:42:24.674342 00:0c:29:bd:fb:4a > Broadcast, ethertype ARP (0x0806), length 42: Request who-has 172.12.1.6 tell 172.12.1.5, length 28
  65. 20:42:24.674394 00:0c:29:bd:fb:4a > 00:0c:29:bd:fb:4a, ethertype ARP (0x0806), length 42: Reply 172.12.1.6 is-at 00:0c:29:bd:fb:4a, length 28
  66. 20:42:24.674398 00:0c:29:bd:fb:4a > 00:0c:29:bd:fb:4a, ethertype IPv4 (0x0800), length 98: 172.12.1.5 > 172.12.1.6: ICMP echo request, id 30730, seq 1, length 64
  67. 20:42:24.674415 00:0c:29:bd:fb:4a > 00:0c:29:bd:fb:4a, ethertype IPv4 (0x0800), length 98: 172.12.1.6 > 172.12.1.5: ICMP echo reply, id 30730, seq 1, length 6

CNI WITH IPVLAN L2

  1. # CNI Config File:
  2. cat /etc/cni/net.d/10-ipvlan.conf
  3. {
  4. "name": "ipvlannet",
  5. "type": "ipvlan",
  6. "master": "ens33",
  7. "mode": "l2",
  8. "ipam": {
  9. "type": "host-local",
  10. "subnet": "172.12.1.0/24",
  11. "rangeStart": "172.12.1.129",
  12. "rangeEnd": "172.12.1.250",
  13. "gateway": "172.12.1.2",
  14. "routes": [
  15. { "dst": "0.0.0.0/0" }
  16. ]
  17. }
  18. }
  19. # bin File:
  20. [root@k8s-1 bin]# pwd
  21. /opt/cni/bin
  22. [root@k8s-1 bin]# ll
  23. total 167524
  24. -rwxr-xr-x 1 root root 4159518 Aug 13 18:28 bandwidth
  25. -rwxr-xr-x. 1 root root 3581192 Sep 10 2020 bridge
  26. -rwxr-xr-x 1 root root 36564992 Aug 13 18:28 calico
  27. -rwxr-xr-x 1 root root 36564992 Aug 13 18:28 calico-ipam
  28. -rwxr-xr-x. 1 root root 9837552 Sep 10 2020 dhcp
  29. -rwxr-xr-x. 1 root root 4699824 Sep 10 2020 firewall
  30. -rwxr-xr-x 1 root root 3069556 Aug 13 18:28 flannel
  31. -rwxr-xr-x. 1 root root 3274160 Sep 10 2020 host-device
  32. -rwxr-xr-x 1 root root 3614480 Aug 13 18:28 host-local
  33. -rwxr-xr-x 1 root root 36564992 Aug 13 18:28 install
  34. -rwxr-xr-x. 1 root root 3377272 Sep 10 2020 ipvlan # this one
  35. -rwxr-xr-x 1 root root 3209463 Aug 13 18:28 loopback
  36. -rwxr-xr-x. 1 root root 3440168 Sep 10 2020 macvlan
  37. -rwxr-xr-x 1 root root 3939867 Aug 13 18:28 portmap
  38. -rwxr-xr-x. 1 root root 3528800 Sep 10 2020 ptp
  39. -rwxr-xr-x. 1 root root 2849328 Sep 10 2020 sbr
  40. -rwxr-xr-x. 1 root root 2503512 Sep 10 2020 static
  41. -rwxr-xr-x 1 root root 3356587 Aug 13 18:28 tuning
  42. -rwxr-xr-x. 1 root root 3377120 Sep 10 2020 vlan
  43. [root@k8s-1 bin]#
  44. #
  45. # Pod resource template:
  46. # cat cni_demo_template.yaml
  47. apiVersion: apps/v1
  48. kind: DaemonSet
  49. metadata:
  50. labels:
  51. app: cni
  52. name: cni
  53. spec:
  54. selector:
  55. matchLabels:
  56. app: cni
  57. template:
  58. metadata:
  59. annotations:
  60. cni: "ipvlannet"
  61. labels:
  62. app: cni
  63. spec:
  64. containers:
  65. - image: burlyluo/nettoolbox
  66. name: nettoolbox
  67. ---
  68. # kubectl get pods -o wide
  69. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  70. cni-4dfnl 1/1 Running 0 55s 172.12.1.130 k8s-2 <none> <none>
  71. cni-prc22 1/1 Running 0 55s 172.12.1.131 k8s-1 <none> <none>
  72. # kubectl exec -it cni-4dfnl -- ifconfig -a

IPVLAN L3

  1. L3 模式
  2. 在 L3 模式 中,虚拟设备只处理 L3 以上的流量。虚拟设备不响应 ARP 请求,用户必须手动为相关点上的 IPVLAN IP 地址配置邻居条目。相关容器的出口流量会放在 default 命名空间的 netfilter POSTROUTING 和 OUTPUT 链上,而入口流量会线程处理,方式与 L2 模式 相同。使用L3 模式会提供很好的控制,但可能会降低网络流量性能。

image.png

  1. # IPVLAN L3:
  2. # 1.Add ns:
  3. ip netns add net1
  4. ip netns add net2
  5. # 2. Set the ipvlan l3 mode:
  6. ip link add ipvlan1 link ens33 type ipvlan mode l3
  7. ip link add ipvlan2 link ens33 type ipvlan mode l3
  8. # 3.Add the interface to ns:
  9. ip link set ipvlan1 netns net1
  10. ip link set ipvlan2 netns net2
  11. # 4.config the ip address
  12. ip netns exec net1 ifconfig ipvlan1 10.1.1.2/24 up
  13. ip netns exec net2 ifconfig ipvlan2 10.1.2.2/24 up
  14. # 5.Add default route
  15. ip netns exec net1 ip route add default dev ipvlan1
  16. ip netns exec net2 ip route add default dev ipvlan2
  17. # ARP:在 L3 模式 中,虚拟设备只处理 L3 以上的流量。虚拟设备不响应 ARP 请求
  18. # ping
  19. [root@k8s-2 ~]# ip netns exec net1 ping 10.1.2.2
  20. PING 10.1.2.2 (10.1.2.2) 56(84) bytes of data.
  21. 64 bytes from 10.1.2.2: icmp_seq=1 ttl=64 time=0.058 ms
  22. ^C
  23. --- 10.1.2.2 ping statistics ---
  24. 1 packets transmitted, 1 received, 0% packet loss, time 0ms
  25. rtt min/avg/max/mdev = 0.058/0.058/0.058/0.000 ms
  26. # capture on interface ipvlan1:
  27. [root@k8s-2 ~]# ip netns exec net1 tcpdump -ne -i ipvlan1
  28. tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
  29. listening on ipvlan1, link-type EN10MB (Ethernet), capture size 262144 bytes
  30. 21:15:58.564501 00:0c:29:e2:bf:86 > 00:0c:29:e2:bf:86, ethertype IPv4 (0x0800), length 98: 10.1.1.2 > 10.1.2.2: ICMP echo request, id 33637, seq 1, length 64
  31. 21:15:58.564536 00:0c:29:e2:bf:86 > 00:0c:29:e2:bf:86, ethertype IPv4 (0x0800), length 98: 10.1.2.2 > 10.1.1.2: ICMP echo reply, id 33637, seq 1, length 64

MULTUS WITH IPVLAN

  1. # https://platform9.com/docs/kubernetes/how-to-luigi---ipvlan
  2. # https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/docs/configuration.md
  3. # network-attachment-definition:
  4. apiVersion: "k8s.cni.cncf.io/v1"
  5. kind: NetworkAttachmentDefinition
  6. metadata:
  7. name: whereabouts-ipvlan-conf-1
  8. spec:
  9. config: '{
  10. "cniVersion": "0.3.0",
  11. "name": "ipvlan-conf-1",
  12. "type": "ipvlan",
  13. "master": "eth2",
  14. "mode": "l2",
  15. "ipam": {
  16. "type": "whereabouts",
  17. "range": "192.168.70.0/24",
  18. "range_start": "192.168.70.20",
  19. "range_end": "192.168.70.50",
  20. "gateway": "192.168.70.1"
  21. }
  22. }'
  23. # Pod template:
  24. apiVersion: v1
  25. kind: Pod
  26. metadata:
  27. name: pod0-case-02
  28. annotations:
  29. k8s.v1.cni.cncf.io/networks: whereabouts-conf-ipvlan
  30. spec:
  31. containers:
  32. - name: pod0-case-02
  33. image: docker.io/centos/tools:latest
  34. command:
  35. - /sbin/init
  36. ---
  37. # cat pod1-case2.yaml
  38. apiVersion: v1
  39. kind: Pod
  40. metadata:
  41. name: pod1-case-02
  42. annotations:
  43. k8s.v1.cni.cncf.io/networks: whereabouts-conf-ipvlan
  44. spec:
  45. containers:
  46. - name: pod1-case-02
  47. image: docker.io/centos/tools:latest
  48. command:
  49. - /sbin/init
  50. # Get pod resources:
  51. $ kubectl get pods -o wide
  52. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  53. pod0-case-02 1/1 Running 0 66m 10.135.1.147 192.168.50.14 <none> <none>
  54. pod1-case-02 1/1 Running 0 62m 10.135.1.148 192.168.50.14 <none> <none>
  55. $ kubectl exec -it pod0-case-02 -- ip -d address
  56. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
  57. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 numtxqueues 1 numrxqueues 1
  58. inet 127.0.0.1/8 scope host lo
  59. valid_lft forever preferred_lft forever
  60. 3: eth0@if25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1472 qdisc noqueue state UP group default
  61. link/ether de:ff:c2:57:c6:e7 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0
  62. veth numtxqueues 1 numrxqueues 1
  63. inet 10.135.1.147/24 brd 10.135.1.255 scope global eth0
  64. valid_lft forever preferred_lft forever
  65. 4: net1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
  66. link/ether fa:16:3e:10:31:25 brd ff:ff:ff:ff:ff:ff promiscuity 0
  67. ipvlan mode l2 numtxqueues 1 numrxqueues 1
  68. inet 192.168.70.20/24 brd 192.168.70.255 scope global net1
  69. valid_lft forever preferred_lft forever
  70. ---
  71. $ kubectl exec -it pod1-case-02 -- ip -d address
  72. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
  73. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 numtxqueues 1 numrxqueues 1
  74. inet 127.0.0.1/8 scope host lo
  75. valid_lft forever preferred_lft forever
  76. 3: eth0@if26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1472 qdisc noqueue state UP group default
  77. link/ether aa:2d:2e:e8:5e:19 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0
  78. veth numtxqueues 1 numrxqueues 1
  79. inet 10.135.1.148/24 brd 10.135.1.255 scope global eth0
  80. valid_lft forever preferred_lft forever
  81. 4: net1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
  82. link/ether fa:16:3e:10:31:25 brd ff:ff:ff:ff:ff:ff promiscuity 0
  83. ipvlan mode l2 numtxqueues 1 numrxqueues 1
  84. inet 192.168.70.21/24 brd 192.168.70.255 scope global net1
  85. valid_lft forever preferred_lft forever
  86. # Ping:
  87. # East-West ipvlan traffic:
  88. $ kubectl exec -it pod1-case-02 -- ping -c 5 192.168.70.20
  89. PING 192.168.70.20 (192.168.70.20) 56(84) bytes of data.
  90. 64 bytes from 192.168.70.20: icmp_seq=1 ttl=64 time=0.317 ms
  91. 64 bytes from 192.168.70.20: icmp_seq=2 ttl=64 time=0.057 ms
  92. 64 bytes from 192.168.70.20: icmp_seq=3 ttl=64 time=0.048 ms
  93. 64 bytes from 192.168.70.20: icmp_seq=4 ttl=64 time=0.056 ms
  94. 64 bytes from 192.168.70.20: icmp_seq=5 ttl=64 time=0.058 ms
  95. --- 192.168.70.20 ping statistics ---
  96. 5 packets transmitted, 5 received, 0% packet loss, time 4000ms
  97. rtt min/avg/max/mdev = 0.048/0.107/0.317/0.105 m
  98. # North-South ipvlan traffic:
  99. $ kubectl exec -it pod0-case-02 -- ping -c 5 192.168.70.1
  100. PING 192.168.70.1 (192.168.70.1) 56(84) bytes of data.
  101. 64 bytes from 192.168.70.1: icmp_seq=1 ttl=64 time=0.893 ms
  102. 64 bytes from 192.168.70.1: icmp_seq=2 ttl=64 time=0.589 ms
  103. 64 bytes from 192.168.70.1: icmp_seq=3 ttl=64 time=0.573 ms
  104. 64 bytes from 192.168.70.1: icmp_seq=4 ttl=64 time=0.590 ms
  105. 64 bytes from 192.168.70.1: icmp_seq=5 ttl=64 time=0.537 ms
  106. --- 192.168.70.1 ping statistics ---
  107. 5 packets transmitted, 5 received, 0% packet loss, time 4002ms
  108. rtt min/avg/max/mdev = 0.537/0.636/0.893/0.131 ms

Multus CNI usage guide

Prerequisites

  • Kubelet configured to use CNI
  • Kubernetes version with CRD support (generally )

Your Kubelet(s) must be configured to run with the CNI network plugin. Please see Kubernetes document for CNI for more details.

Install Multus

Generally we recommend two options: Manually place a Multus binary in your /opt/cni/bin, or use our quick-start method — which creates a daemonset that has an opinionated way of how to install & configure Multus CNI (recommended).

Copy Multus Binary into place

You may acquire the Multus binary via compilation (see the developer guide) or download the a binary from the GitHub releases page. Copy multus binary into CNI binary directory, usually /opt/cni/bin. Perform this on all nodes in your cluster (master and nodes).

  1. $ cp multus /opt/cni/bin

Via Daemonset method
As a quickstart, you may apply these YAML files (included in the clone of this repository). Run this command (typically you would run this on the master, or wherever you have access to the kubectl command to manage your cluster).

  1. $ cat ./images/{multus-daemonset.yml,flannel-daemonset.yml} | kubectl apply -f -

If you need more comprehensive detail, continue along with this guide, otherwise, you may wish to either follow the quickstart guide or skip to the ‘Create network attachment definition’ section.

Set up conf file in /etc/cni/net.d/ (Installed automatically by Daemonset)

If you use daemonset to install multus, skip this section and go to “Create network attachment”
You put CNI config file in /etc/cni/net.d. Kubernetes CNI runtime uses the alphabetically first file in the directory. ("NOTE1", "NOTE2" are just comments, you can remove them at your configuration)
Execute following commands at all Kubernetes nodes (i.e. master and minions)

  1. $ mkdir -p /etc/cni/net.d
  2. $ cat >/etc/cni/net.d/00-multus.conf <<EOF
  3. {
  4. "name": "multus-cni-network",
  5. "type": "multus",
  6. "readinessindicatorfile": "/var/run/flannel/subnet.env",
  7. "delegates": [
  8. {
  9. "NOTE1": "This is example, wrote your CNI config in delegates",
  10. "NOTE2": "If you use flannel, you also need to run flannel daemonset before!",
  11. "type": "flannel",
  12. "name": "flannel.1",
  13. "delegate": {
  14. "isDefaultGateway": true
  15. }
  16. }
  17. ],
  18. "kubeconfig": "/etc/cni/net.d/multus.d/multus.kubeconfig"
  19. }
  20. EOF

For the detail, please take a look into Configuration Reference
NOTE: You can use “clusterNetwork”/“defaultNetworks” instead of “delegates”, see for the detail
As above config, you need to set "kubeconfig" in the config file for NetworkAttachmentDefinition(CRD).

Which network will be used for “Pod IP”?

In case of “delegates”, the first delegates network will be used for “Pod IP”. Otherwise, “clusterNetwork” will be used for “Pod IP”.

Create ServiceAccount, ClusterRole and its binding

Create resources for multus to access CRD objects as following command:

  1. # Execute following commands at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: v1
  4. kind: ServiceAccount
  5. metadata:
  6. name: multus
  7. namespace: kube-system
  8. ---
  9. kind: ClusterRole
  10. apiVersion: rbac.authorization.k8s.io/v1beta1
  11. metadata:
  12. name: multus
  13. rules:
  14. - apiGroups: ["k8s.cni.cncf.io"]
  15. resources:
  16. - '*'
  17. verbs:
  18. - '*'
  19. - apiGroups:
  20. - ""
  21. resources:
  22. - pods
  23. - pods/status
  24. verbs:
  25. - get
  26. - update
  27. ---
  28. kind: ClusterRoleBinding
  29. apiVersion: rbac.authorization.k8s.io/v1beta1
  30. metadata:
  31. name: multus
  32. roleRef:
  33. apiGroup: rbac.authorization.k8s.io
  34. kind: ClusterRole
  35. name: multus
  36. subjects:
  37. - kind: ServiceAccount
  38. name: multus
  39. namespace: kube-system
  40. EOF

Set up kubeconfig file

Create kubeconfig at master node as following commands:

  1. # Execute following command at Kubernetes master
  2. $ mkdir -p /etc/cni/net.d/multus.d
  3. $ SERVICEACCOUNT_CA=$(kubectl get secrets -n=kube-system -o json | jq -r '.items[]|select(.metadata.annotations."kubernetes.io/service-account.name"=="multus")| .data."ca.crt"')
  4. $ SERVICEACCOUNT_TOKEN=$(kubectl get secrets -n=kube-system -o json | jq -r '.items[]|select(.metadata.annotations."kubernetes.io/service-account.name"=="multus")| .data.token' | base64 -d )
  5. $ KUBERNETES_SERVICE_PROTO=$(kubectl get all -o json | jq -r .items[0].spec.ports[0].name)
  6. $ KUBERNETES_SERVICE_HOST=$(kubectl get all -o json | jq -r .items[0].spec.clusterIP)
  7. $ KUBERNETES_SERVICE_PORT=$(kubectl get all -o json | jq -r .items[0].spec.ports[0].port)
  8. $ cat > /etc/cni/net.d/multus.d/multus.kubeconfig <<EOF
  9. # Kubeconfig file for Multus CNI plugin.
  10. apiVersion: v1
  11. kind: Config
  12. clusters:
  13. - name: local
  14. cluster:
  15. server: ${KUBERNETES_SERVICE_PROTOCOL:-https}://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}
  16. certificate-authority-data: ${SERVICEACCOUNT_CA}
  17. users:
  18. - name: multus
  19. user:
  20. token: "${SERVICEACCOUNT_TOKEN}"
  21. contexts:
  22. - name: multus-context
  23. context:
  24. cluster: local
  25. user: multus
  26. current-context: multus-context
  27. EOF

Copy /etc/cni/net.d/multus.d/multus.kubeconfig into other Kubernetes nodes
NOTE: Recommend to exec ‘chmod 600 /etc/cni/net.d/multus.d/multus.kubeconfig’ to keep secure

  1. $ scp /etc/cni/net.d/multus.d/multus.kubeconfig ...

Setup CRDs (daemonset automatically does)

If you use daemonset to install multus, skip this section and go to “Create network attachment”
Create CRD definition in Kubernetes as following command at master node:

  1. # Execute following command at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: apiextensions.k8s.io/v1beta1
  4. kind: CustomResourceDefinition
  5. metadata:
  6. name: network-attachment-definitions.k8s.cni.cncf.io
  7. spec:
  8. group: k8s.cni.cncf.io
  9. version: v1
  10. scope: Namespaced
  11. names:
  12. plural: network-attachment-definitions
  13. singular: network-attachment-definition
  14. kind: NetworkAttachmentDefinition
  15. shortNames:
  16. - net-attach-def
  17. validation:
  18. openAPIV3Schema:
  19. properties:
  20. spec:
  21. properties:
  22. config:
  23. type: string
  24. EOF

Create network attachment definition

The ‘NetworkAttachmentDefinition’ is used to setup the network attachment, i.e. secondary interface for the pod, There are two ways to configure the ‘NetworkAttachmentDefinition’ as following:

  • NetworkAttachmentDefinition with json CNI config
  • NetworkAttachmentDefinition with CNI config file

    NetworkAttachmentDefinition with json CNI config:

    Following command creates NetworkAttachmentDefinition. CNI config is in config: field.
    1. # Execute following command at Kubernetes master
    2. $ cat <<EOF | kubectl create -f -
    3. apiVersion: "k8s.cni.cncf.io/v1"
    4. kind: NetworkAttachmentDefinition
    5. metadata:
    6. name: macvlan-conf-1
    7. spec:
    8. config: '{
    9. "cniVersion": "0.3.0",
    10. "type": "macvlan",
    11. "master": "eth1",
    12. "mode": "bridge",
    13. "ipam": {
    14. "type": "host-local",
    15. "ranges": [
    16. [ {
    17. "subnet": "10.10.0.0/16",
    18. "rangeStart": "10.10.1.20",
    19. "rangeEnd": "10.10.3.50",
    20. "gateway": "10.10.0.254"
    21. } ]
    22. ]
    23. }
    24. }'
    25. EOF

    NetworkAttachmentDefinition with CNI config file:

    If NetworkAttachmentDefinition has no spec, multus find a file in defaultConfDir (‘/etc/cni/multus/net.d’, with same name in the ‘name’ field of CNI config.
    1. # Execute following command at Kubernetes master
    2. $ cat <<EOF | kubectl create -f -
    3. apiVersion: "k8s.cni.cncf.io/v1"
    4. kind: NetworkAttachmentDefinition
    5. metadata:
    6. name: macvlan-conf-2
    7. EOF
  1. # Execute following commands at all Kubernetes nodes (i.e. master and minions)
  2. $ cat <<EOF > /etc/cni/multus/net.d/macvlan2.conf
  3. {
  4. "cniVersion": "0.3.0",
  5. "type": "macvlan",
  6. "name": "macvlan-conf-2",
  7. "master": "eth1",
  8. "mode": "bridge",
  9. "ipam": {
  10. "type": "host-local",
  11. "ranges": [
  12. [ {
  13. "subnet": "11.10.0.0/16",
  14. "rangeStart": "11.10.1.20",
  15. "rangeEnd": "11.10.3.50"
  16. } ]
  17. ]
  18. }
  19. }

Run pod with network annotation

Launch pod with text annotation

  1. # Execute following command at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: v1
  4. kind: Pod
  5. metadata:
  6. name: pod-case-01
  7. annotations:
  8. k8s.v1.cni.cncf.io/networks: macvlan-conf-1, macvlan-conf-2
  9. spec:
  10. containers:
  11. - name: pod-case-01
  12. image: docker.io/centos/tools:latest
  13. command:
  14. - /sbin/init
  15. EOF

Launch pod with text annotation for NetworkAttachmentDefinition in different namespace

You can also specify NetworkAttachmentDefinition with its namespace as adding <namespace>/

  1. # Execute following command at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: "k8s.cni.cncf.io/v1"
  4. kind: NetworkAttachmentDefinition
  5. metadata:
  6. name: macvlan-conf-3
  7. namespace: testns1
  8. spec:
  9. config: '{
  10. "cniVersion": "0.3.0",
  11. "type": "macvlan",
  12. "master": "eth1",
  13. "mode": "bridge",
  14. "ipam": {
  15. "type": "host-local",
  16. "ranges": [
  17. [ {
  18. "subnet": "12.10.0.0/16",
  19. "rangeStart": "12.10.1.20",
  20. "rangeEnd": "12.10.3.50"
  21. } ]
  22. ]
  23. }
  24. }'
  25. EOF
  26. $ cat <<EOF | kubectl create -f -
  27. apiVersion: v1
  28. kind: Pod
  29. metadata:
  30. name: pod-case-02
  31. annotations:
  32. k8s.v1.cni.cncf.io/networks: testns1/macvlan-conf-3
  33. spec:
  34. containers:
  35. - name: pod-case-02
  36. image: docker.io/centos/tools:latest
  37. command:
  38. - /sbin/init
  39. EOF

Launch pod with text annotation with interface name

You can also specify interface name as adding @<ifname>.

  1. # Execute following command at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: v1
  4. kind: Pod
  5. metadata:
  6. name: pod-case-03
  7. annotations:
  8. k8s.v1.cni.cncf.io/networks: macvlan-conf-1@macvlan1
  9. spec:
  10. containers:
  11. - name: pod-case-03
  12. image: docker.io/centos/tools:latest
  13. command:
  14. - /sbin/init
  15. EOF

Launch pod with json annotation

  1. # Execute following command at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: v1
  4. kind: Pod
  5. metadata:
  6. name: pod-case-04
  7. annotations:
  8. k8s.v1.cni.cncf.io/networks: '[
  9. { "name" : "macvlan-conf-1" },
  10. { "name" : "macvlan-conf-2" }
  11. ]'
  12. spec:
  13. containers:
  14. - name: pod-case-04
  15. image: docker.io/centos/tools:latest
  16. command:
  17. - /sbin/init
  18. EOF

Launch pod with json annotation for NetworkAttachmentDefinition in different namespace

You can also specify NetworkAttachmentDefinition with its namespace as adding "namespace": "<namespace>".

  1. # Execute following command at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: v1
  4. kind: Pod
  5. metadata:
  6. name: pod-case-05
  7. annotations:
  8. k8s.v1.cni.cncf.io/networks: '[
  9. { "name" : "macvlan-conf-1",
  10. "namespace": "testns1" }
  11. ]'
  12. spec:
  13. containers:
  14. - name: pod-case-05
  15. image: docker.io/centos/tools:latest
  16. command:
  17. - /sbin/init
  18. EOF

Launch pod with json annotation with interface

You can also specify interface name as adding "interface": "<ifname>".

  1. # Execute following command at Kubernetes master
  2. $ cat <<EOF | kubectl create -f -
  3. apiVersion: v1
  4. kind: Pod
  5. metadata:
  6. name: pod-case-06
  7. annotations:
  8. k8s.v1.cni.cncf.io/networks: '[
  9. { "name" : "macvlan-conf-1",
  10. "interface": "macvlan1" },
  11. { "name" : "macvlan-conf-2" }
  12. ]'
  13. spec:
  14. containers:
  15. - name: pod-case-06
  16. image: docker.io/centos/tools:latest
  17. command:
  18. - /sbin/init
  19. EOF

Verifying pod network

Following the example of ip -d address output of above pod, “pod-case-06”:

  1. # Execute following command at Kubernetes master
  2. $ kubectl exec -it pod-case-06 -- ip -d address
  3. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
  4. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
  5. inet 127.0.0.1/8 scope host lo
  6. valid_lft forever preferred_lft forever
  7. inet6 ::1/128 scope host
  8. valid_lft forever preferred_lft forever
  9. 3: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default
  10. link/ether 0a:58:0a:f4:02:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0
  11. veth numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
  12. inet 10.244.2.6/24 scope global eth0
  13. valid_lft forever preferred_lft forever
  14. inet6 fe80::ac66:45ff:fe7c:3a19/64 scope link
  15. valid_lft forever preferred_lft forever
  16. 4: macvlan1@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
  17. link/ether 4e:6d:7a:4e:14:87 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0
  18. macvlan mode bridge numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
  19. inet 10.10.1.22/16 scope global macvlan1
  20. valid_lft forever preferred_lft forever
  21. inet6 fe80::4c6d:7aff:fe4e:1487/64 scope link
  22. valid_lft forever preferred_lft forever
  23. 5: net2@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
  24. link/ether 6e:e3:71:7f:86:f7 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0
  25. macvlan mode bridge numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
  26. inet 11.10.1.22/16 scope global net2
  27. valid_lft forever preferred_lft forever
  28. inet6 fe80::6ce3:71ff:fe7f:86f7/64 scope link
  29. valid_lft forever preferred_lft forever
Interface name Description
lo loopback
eth0 Default network interface (flannel)
macvlan1 macvlan interface (macvlan-conf-1)
net2 macvlan interface (macvlan-conf-2)

Specifying a default route for a specific attachment

Typically, the default route for a pod will route traffic over the eth0 and therefore over the cluster-wide default network. You may wish to specify that a different network attachment will have the default route.
You can achieve this by using the JSON formatted annotation and specifying a default-route key.
NOTE: It’s important that you consider that this may impact some functionality of getting traffic to route over the cluster-wide default network.
For example, we have a this configuration for macvlan:

  1. cat <<EOF | kubectl create -f -
  2. apiVersion: "k8s.cni.cncf.io/v1"
  3. kind: NetworkAttachmentDefinition
  4. metadata:
  5. name: macvlan-conf
  6. spec:
  7. config: '{
  8. "cniVersion": "0.3.0",
  9. "type": "macvlan",
  10. "master": "eth0",
  11. "mode": "bridge",
  12. "ipam": {
  13. "type": "host-local",
  14. "subnet": "192.168.2.0/24",
  15. "rangeStart": "192.168.2.200",
  16. "rangeEnd": "192.168.2.216",
  17. "routes": [
  18. { "dst": "0.0.0.0/0" }
  19. ],
  20. "gateway": "192.168.2.1"
  21. }
  22. }'
  23. EOF

We can then create a pod which uses the default-route key in the JSON formatted k8s.v1.cni.cncf.io/networks annotation.

  1. cat <<EOF | kubectl create -f -
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: samplepod
  6. annotations:
  7. k8s.v1.cni.cncf.io/networks: '[{
  8. "name": "macvlan-conf",
  9. "default-route": ["192.168.2.1"]
  10. }]'
  11. spec:
  12. containers:
  13. - name: samplepod
  14. command: ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"]
  15. image: dougbtv/centos-network
  16. EOF

This will set 192.168.2.1 as the default route over the net1 interface, such as:

  1. $ kubectl exec -it samplepod -- ip route
  2. default via 192.168.2.1 dev net1
  3. 10.244.0.0/24 dev eth0 proto kernel scope link src 10.244.0.169
  4. 10.244.0.0/16 via 10.244.0.1 dev eth0

Entrypoint Parameters

Multus CNI, when installed using the daemonset-style installation uses an entrypoint script which copies the Multus binary into place, places CNI configurations. This entrypoint takes a variety of parameters for customization.
Typically, you’d modified the daemonset YAML itself to specify these parameters.
For example, the command and args parameters in the containers section of the DaemonSet may look something like:

  1. command: ["/entrypoint.sh"]
  2. args:
  3. - "--multus-conf-file=auto"
  4. - "--namespace-isolation=true"
  5. - "--multus-log-level=verbose"

Note that some of the defaults have directories inside the root directory named /host/, this is because it is deployed as a container and we have host file system locations mapped into this directory inside the container. If you use other directories, you may have to change the mounted volumes.

Entrypoint script parameters

Each parameter is shown with the default as the value.

  1. --cni-conf-dir=/host/etc/cni/net.d

This is the configuration directory where Multus will write its configuration file.

  1. --cni-bin-dir=/host/opt/cni/bin

This the directory in which the Multus binary will be installed.

  1. --namespace-isolation=false

Setting this option to true enables the Namespace isolation feature, which insists that custom resources must be created in the same namespace as the pods, otherwise it will refuse to attach those definitions as additional interfaces. See (the configuration guide for more information)[configuration.md].

  1. --global-namespaces=default,foo,bar

The --global-namespaces works only when --namespace-isolation=true. This takes a comma-separated list of namespaces which can be referred to globally when namespace isolation is enabled. See (the configuration guide for more information)[configuration.md].

  1. --multus-bin-file=/usr/src/multus-cni/bin/multus

This option lets you set which binary executable to copy from the container onto the host (into the directory specified by --cni-bin-dir), allowing one to copy an alternate version or build of Multus CNI.

  1. --multus-conf-file=/usr/src/multus-cni/images/70-multus.conf

The --multus-conf-file is one of two options; it can be set to a source file to be copied into the location specified by --cni-conf-dir. Or, to a value of auto, that is: --multus-conf-file=auto.
The automatic configuration option is used to automatically generate Multus configurations given existing on-disk CNI configurations for your default network.
In the case that --multus-conf-file=auto — The entrypoint script will look at the --multus-autoconfig-dir (by default, the same as the --cni-conf-dir). Multus will wait (600 seconds) until there’s a CNI configuration file there, and it will take the alphabetically first configuration there, and it will wrap that configuration into a Multus configuration.

  1. --multus-autoconfig-dir=/host/etc/cni/net.d

Used only with --multus-conf-file=auto. This option allows one to set which directory will be used to generate configuration files.
This can be used if you have your CNI configuration stored in an alternate location, or, you have constraints on race conditions where you’d like to generate your default network configuration first, and then only have Multus write its configuration when it finds that configuration — allowing only Multus to write the CNI configuration in the --cni-conf-dir, therefore notifying the Kubelet that the node is in a ready state.

  1. --multus-kubeconfig-file-host=/etc/cni/net.d/multus.d/multus.kubeconfig

Used only with --multus-conf-file=auto. Allows you to specify an alternate path to the Kubeconfig.

  1. --multus-master-cni-file-name=

The --multus-master-cni-file-name can be used to select the cni file as the master cni, rather than the first file in cni-conf-dir. For example, --multus-master-cni-file-name=10-calico.conflist.

  1. --multus-log-level=
  2. --multus-log-file=

Used only with --multus-conf-file=auto. See the documentation for logging for which values are permitted.
Used only with --multus-conf-file=auto. Allows you to specify CNI spec version. Please set if you need to speicfy CNI spec version.

  1. --cni-version=

In some cases, the original CNI configuration that the Multus configuration was generated from (using --multus-conf-file=auto) may be used as a sort of semaphor for network readiness — as this model is used by the Kubelet itself. If you need to disable Multus’ availablity, you may wish to clean out the generated configuration file when the source file for autogeneration of the config file is no longer present. You can use this functionality by setting:

  1. --cleanup-config-on-exit=true

When using CRIO, you may need to restart CRIO to get the Multus configuration file to take — this is rarely necessary.

  1. --restart-crio=false

Additionally when using CRIO, you may wish to have the CNI config file that’s used as the source for --multus-conf-file=auto renamed. This boolean option when set to true automatically renames the file with a .old suffix to the original filename.

  1. --rename-conf-file=true

When using --multus-conf-file=auto you may also care to specify a binDir in the configuration, this can be accomplished using the --additional-bin-dir option.

  1. --additional-bin-dir=/opt/multus/bin

Sometimes, you may wish to not have the entrypoint copy the binary file onto the host. Potentially, you have another way to copy in a specific version of Multus, for example. By default, it’s always copied, but you may disable the copy with:

  1. --skip-multus-binary-copy=true

If you wish to have auto configuration use the readinessindicatorfile in the configuration, you can use the --readiness-indicator-file to express which file should be used as the readiness indicator.

  1. --readiness-indicator-file=/path/to/file
  1. # Above datae:
  2. # Latest commit ec30b99 on Jun 2

CNI-IPVLAN-VPC-K8S

  1. he plugins are designed to be straightforward to configure and deploy within a VPC. Kubelets boot and then self-configure and scale their IP usage as needed, without requiring the often recommended complexities of administering overlay networks, BGP, disabling source/destination checks, or adjusting VPC route tables to provide per-instance subnets to each host (which is limited to 50-100 entries per VPC). In short, cni-ipvlan-vpc-k8s significantly reduces the network complexity required to deploy Kubernetes at scale within AWS.
  2. The maximum number of Pods per AWS instance is determined by ENI limits. Instance types offering 8 ENIs can scale up to and beyond the default Kubernetes limit of 110 pods per instance.
  3. # Features
  4. Designed and tested on Kubernetes in AWS (v1.10 with cri-o, docker, and containerd)
  5. No overlay network; very low overhead with IPvlan
  6. No external or local network services required outside of the AWS EC2 API; host-local scale up and scale down of network resources
  7. Unnumbered point-to-point interfaces connect Pods with their Kubelet and Daemon Sets using their well-known Kubernetes IPs and optionally provide IPv4 internet connectivity via NAT by directing traffic over the primary private IP of the boot ENI making use of Amazon's Public IPv4 addressing attribute feature.
  8. No asymmetric routing; no VPC routing table changes required
  9. Pod IPs are directly addressable from non-Kubernetes VPC hosts, easing migration of existing pre-Kubernetes service meshes and infrastructure.
  10. Automatic discovery of AWS resources, minimal plugin configuration required.
  1. # How it Works
  2. The primary EC2 boot ENI with its primary private IP is used as the IP address for the node. Our CNI plugins manage additional ENIs and private IPs on those ENIs to assign IP addresses to Pods.
  3. Each Pod contains two network interfaces, a primary IPvlan interface and an unnumbered point-to-point virtual ethernet interface. These interfaces are created via a chained CNI execution.

20210822-IPVLAN L2&L3 Mode - 图3

  1. IPvlan interface: The IPvlan interface with the Pod’s IP is used for all VPC traffic and provides minimal overhead for network packet processing within the Linux kernel. The master device is the ENI of the associated Pod IP. IPvlan is used in L2 mode with isolation provided from all other ENIs, including the boot ENI handling traffic for the Kubernetes control plane.
  2. Unnumbered point-to-point interface: A pair of virtual ethernet interfaces (veth) without IP addresses is used to interconnect the Pod’s network namespace to the default network namespace. The interface is used as the default route (non-VPC traffic) from the Pod and additional routes are created on each side to direct traffic between the node IP and the Pod IP over the link. For traffic sent over the interface, the Linux kernel borrows the IP address from the IPvlan interface for the Pod side and the boot ENI interface for the Kubelet side. Kubernetes Pods and nodes communicate using the same well-known addresses regardless of which interface (IPvlan or veth) is used for communication. This particular trick of “IP unnumbered configuration” is documented in RFC5309.