# Kubernetes CNI Multus+SRIOV Kernel+Bond CNI# 时间:20210829-[14:00-17:00]# 主题:SRIOV Bond CNI# 文档:https://www.yuque.com/docs/share/05fe4d0b-41ca-4d71-817f-4f859b13dd67?# 《20210829-Multus+SRIOV+Bond CNI》# 作业:Multus With SRIOV Bond CNI
# FAQ: SRIOV-DPDK can't use this Bond CNI:# https://01.org/kubernetes/projects/bond-cni# https://github.com/intel/bond-cni/issues/23This configuration is only applicable to SRIOV VFs using the kernel driver. Userspace driver VFs - such as those used in DPDK workloads - can not be bonded with the Bond CNI.
SRIOV CNI之Bond
# env infomation:# uname -a Linux my-cluster-worker0 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux# kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME10.2.10.21 Ready worker 8d v1.19.6 10.2.10.21 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 docker://19.3.1110.2.10.24 Ready master 8d v1.19.6 10.2.10.24 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 docker://19.3.11# 我们需要实现SRIOV的vf之间的bond。# 原理为创建两个SRIOV NAD net1 和 net2.然后再创建一个bond的NAD把net1和net2加进这个bond。# Reference:# https://github.com/intel/bond-cni# Note:此环境需要就绪Multus + SRIOV CNI + SRIOV-NETWORK-DEVICE-Plugin + IPAM(host-local or whereabouts)# kubectl get pods -o wide -nkube-system NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATEScalico-kube-controllers-696568f84b-t5mbh 1/1 Running 2 8d 10.30.9.3 10.2.10.24 <none> <none>calico-node-5wvd2 1/1 Running 0 8d 10.2.10.24 10.2.10.24 <none> <none>calico-node-v6pcl 1/1 Running 2 8d 10.2.10.21 10.2.10.21 <none> <none>calico-typha-7dc9b96b74-c7626 1/1 Running 0 8d 10.2.10.24 10.2.10.24 <none> <none>kube-multus-ds-amd64-2jnth 1/1 Running 2 8d 10.2.10.21 10.2.10.21 <none> <none> # Multus CNIkube-multus-ds-amd64-7blfh 1/1 Running 0 8d 10.2.10.24 10.2.10.24 <none> <none>kube-sriov-cni-ds-amd64-dxhfz 1/1 Running 2 8d 10.2.10.21 10.2.10.21 <none> <none> # SRIOV CNIkube-sriov-cni-ds-amd64-x4x5n 1/1 Running 0 8d 10.2.10.24 10.2.10.24 <none> <none>kube-sriov-device-plugin-amd64-7fgzb 1/1 Running 2 8d 10.2.10.21 10.2.10.21 <none> <none> # SRIOV Network Device Pluginkube-sriov-device-plugin-amd64-sm7r8 1/1 Running 0 8d 10.2.10.24 10.2.10.24 <none> <none>whereabouts-22zzs 1/1 Running 0 8d 10.2.10.24 10.2.10.24 <none> <none> # IPAM(whereabouts or host-local)whereabouts-nmk8z 1/1 Running 2 8d 10.2.10.21 10.2.10.21 <none> <none># Multus CNI: https://github.com/k8snetworkplumbingwg/multus-cni# SRIOV CNI: https://github.com/k8snetworkplumbingwg/sriov-cni# SRIOV NETWORK DEVICE Plugin: https://github.com/k8snetworkplumbingwg/sriov-network-device-plugin# IPAM(whereabouts): https://github.com/k8snetworkplumbingwg/whereabouts# IPAM(host-local): https://www.cni.dev/plugins/current/ipam/host-local/
NetworkAttachmentDefinition
# sriov 环境介绍:# cat configMap.yaml apiVersion: v1kind: ConfigMapmetadata: name: sriovdp-config namespace: kube-systemdata: config.json: | { "resourceList": [ { "resourceName": "sriov_kern_1", "selectors": { "vendors": ["8086"], "devices": ["154c"], "drivers": ["i40evf"], "pfNames": ["eth4"] } }, { "resourceName": "sriov_kern_2", "selectors": { "vendors": ["8086"], "devices": ["154c"], "drivers": ["i40evf"], "pfNames": ["eth5"] } }, { "resourceName": "sriov_dpdk_3", "selectors": { "vendors": ["8086"], "devices": ["154c"], "drivers": ["igb_uio"], "pfNames": ["eth6"] } }, { "resourceName": "sriov_dpdk_4", "selectors": { "vendors": ["8086"], "devices": ["154c"], "drivers": ["igb_uio"], "pfNames": ["eth7"] } } ] }###################################net1 的NAD来自sriov_kern_1net2 的NAD来自sriov_kern_2bond 的NAD来自net1 + net2#################################### 1.创建net1的NAD:# cat nad-net1.yaml apiVersion: "k8s.cni.cncf.io/v1"kind: NetworkAttachmentDefinitionmetadata: name: net1 annotations: k8s.v1.cni.cncf.io/resourceName: intel.com/sriov_kern_1spec: config: '{ "type": "sriov", "cniVersion": "0.3.1", "name": "sriov-kernelnet0", "spoofchk": "off", "type": "sriov"}'# 2.创建net2的NAD:# cat nad-net2.yaml apiVersion: "k8s.cni.cncf.io/v1"kind: NetworkAttachmentDefinitionmetadata: name: net2 annotations: k8s.v1.cni.cncf.io/resourceName: intel.com/sriov_kern_2spec: config: '{ "type": "sriov", "cniVersion": "0.3.1", "name": "sriov-kernelnet0", "spoofchk": "off", "type": "sriov"}'# 3.创建bond的NAD:# cat bond.yaml apiVersion: "k8s.cni.cncf.io/v1"kind: NetworkAttachmentDefinitionmetadata: name: bondspec: config: '{ "type": "bond", "cniVersion": "0.3.1", "name": "bond", "ifname": "bond0", "mode": "active-backup", "failOverMac": 1, "linksInContainer": true, "miimon": "100", "links": [ {"name": "net1"}, {"name": "net2"} ], "ipam": { "type": "host-local", "subnet": "10.56.217.0/24", "routes": [{ "dst": "0.0.0.0/0" }], "gateway": "10.56.217.1" }}'## Network configuration referencename (string, required): the name of the networktype (string, required): "bond"ifname (string, optional): name of the bond interfacemiimon (int, required): specifies the arp link monitoring frequency in millisecondsfailOverMac (int, optional): specifies the failOverMac setting for the bond. Should be set to 1 for active-backup bond modes. Default is 0.linksInContainer(boolean, optional): specifies if slave links are in container to start. Default is false i.e. look for interfaces on host before bonding.links (dictionary, required): master interface namesipam (dictionary, required): IPAM configuration to be used for this network
创建Pod
# 1. 名称空间net1中Pod的配置:apiVersion: v1kind: Podmetadata: name: pod-bond annotations: k8s.v1.cni.cncf.io/networks: '[{"name": "net1","interface": "net1"},{"name": "net2","interface": "net2"},{"name": "bond","interface": "bond0"}]'spec: restartPolicy: Never containers: - name: bond-test image: centos/tools:v1 imagePullPolicy: IfNotPresent command: - /sbin/init resources: requests: intel.com/sriov_kern_1: '1' intel.com/sriov_kern_2: '1' limits: intel.com/sriov_kern_1: '1' intel.com/sriov_kern_2: '1'# 2.名称空间net1中Pod的配置:apiVersion: v1kind: Podmetadata: name: pod-bond annotations: k8s.v1.cni.cncf.io/networks: '[{"name": "net1","interface": "net1"},{"name": "net2","interface": "net2"},{"name": "bond","interface": "bond0"}]'spec: restartPolicy: Never containers: - name: bond-test image: centos/tools:v1 imagePullPolicy: IfNotPresent command: - /sbin/init resources: requests: intel.com/sriov_kern_1: '1' intel.com/sriov_kern_2: '1' limits: intel.com/sriov_kern_1: '1' intel.com/sriov_kern_2: '1'# 为了方便,我们直接在kubectl apply -f xx.yaml 的时候加上名称空间:# kubectl -nnet1 apply -f xx.yaml# kubectl -nnet2 apply -f xx.yaml这样就可轻松使用一个模板创建两个Pod了。
Pod信息查询
# 1.net1 ns中的pod的信息:# kubectl -nnet1 exec -it pod-bond -- ifconfig bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500 # bond 网卡 inet 10.56.217.2 netmask 255.255.255.0 broadcast 0.0.0.0 ether e2:04:af:1f:35:1a txqueuelen 1000 (Ethernet) RX packets 8065 bytes 516230 (504.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 476 (476.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1440 inet 10.20.45.240 netmask 255.255.255.255 broadcast 0.0.0.0 ether 6e:d2:c1:52:d1:bd txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0net1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether e2:04:af:1f:35:1a txqueuelen 1000 (Ethernet) RX packets 4034 bytes 258246 (252.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 476 (476.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0net2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether e2:92:59:1e:df:c0 txqueuelen 1000 (Ethernet) RX packets 4031 bytes 257984 (251.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0# 2.net2 ns中的pod的信息:# kubectl -nnet2 exec -it pod-bond -- ifconfig bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500 # bond 网卡 inet 10.56.217.3 netmask 255.255.255.0 broadcast 0.0.0.0 ether 0a:16:3c:70:54:a3 txqueuelen 1000 (Ethernet) RX packets 7204 bytes 461148 (450.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 476 (476.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1440 inet 10.20.45.16 netmask 255.255.255.255 broadcast 0.0.0.0 ether 02:57:5a:2c:62:0b txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0net1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 0a:16:3c:70:54:a3 txqueuelen 1000 (Ethernet) RX packets 3604 bytes 230748 (225.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 476 (476.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0net2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500 ether 7a:29:7c:be:66:95 txqueuelen 1000 (Ethernet) RX packets 3600 bytes 230400 (225.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Ping测试
# ping# kubectl -nnet2 exec -it pod-bond -- ping 10.56.217.2PING 10.56.217.2 (10.56.217.2) 56(84) bytes of data.64 bytes from 10.56.217.2: icmp_seq=1 ttl=64 time=0.120 ms64 bytes from 10.56.217.2: icmp_seq=2 ttl=64 time=0.091 ms^C--- 10.56.217.2 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 999msrtt min/avg/max/mdev = 0.091/0.105/0.120/0.017 ms
关于SRIOV DPDK
# 1.创建net1的NAD:# cat nad-net1.yaml apiVersion: "k8s.cni.cncf.io/v1"kind: NetworkAttachmentDefinitionmetadata: name: net1 annotations: k8s.v1.cni.cncf.io/resourceName: intel.com/sriov_dpdk_3spec: config: '{ "type": "sriov", "cniVersion": "0.3.1", "name": "sriov-kernelnet0", "spoofchk": "off", "type": "sriov"}'# 2.创建net2的NAD:# cat nad-net2.yaml apiVersion: "k8s.cni.cncf.io/v1"kind: NetworkAttachmentDefinitionmetadata: name: net2 annotations: k8s.v1.cni.cncf.io/resourceName: intel.com/sriov_dpdk_4spec: config: '{ "type": "sriov", "cniVersion": "0.3.1", "name": "sriov-kernelnet0", "spoofchk": "off", "type": "sriov"}'# 3.创建bond的NAD:# cat bond.yaml apiVersion: "k8s.cni.cncf.io/v1"kind: NetworkAttachmentDefinitionmetadata: name: bondspec: config: '{ "type": "bond", "cniVersion": "0.3.1", "name": "bond", "ifname": "bond0", "mode": "active-backup", "failOverMac": 1, "linksInContainer": true, "miimon": "100", "links": [ {"name": "net1"}, {"name": "net2"} ]}'# Pod:# 1. 名称空间net1中Pod的配置:apiVersion: v1kind: Podmetadata: name: pod-bond annotations: k8s.v1.cni.cncf.io/networks: '[{"name": "net1","interface": "net1"},{"name": "net2","interface": "net2"},{"name": "bond","interface": "bond0"}]'spec: restartPolicy: Never containers: - name: bond-test image: centos/tools:v1 imagePullPolicy: IfNotPresent command: - /sbin/init resources: requests: intel.com/sriov_dpdk_3: '1' intel.com/sriov_dpdk_4: '1' limits: intel.com/sriov_dpdk_3: '1' intel.com/sriov_dpdk_4: '1'# 2.名称空间net1中Pod的配置:apiVersion: v1kind: Podmetadata: name: pod-bond annotations: k8s.v1.cni.cncf.io/networks: '[{"name": "net1","interface": "net1"},{"name": "net2","interface": "net2"},{"name": "bond","interface": "bond0"}]'spec: restartPolicy: Never containers: - name: bond-test image: centos/tools:v1 imagePullPolicy: IfNotPresent command: - /sbin/init resources: requests: intel.com/sriov_dpdk_3: '1' intel.com/sriov_dpdk_4: '1' limits: intel.com/sriov_dpdk_3: '1' intel.com/sriov_dpdk_4: '1'##但是其log显示:0399bde5fa556692257101cd15ca0264d5a87fdbbf2f0c29" network for pod "pod-bond": networkPlugin cni failed to set up pod "pod-bond_net1" network: [net1/pod-bond:bond]: error adding container to network "bond": Failed to retrieve link objects from configuration file (&{NetConf:{CNIVersion:0.3.1 Name:bond Type:bond Capabilities:map[] IPAM:{Type:host-local} DNS:{Nameservers:[] Domain: Search:[] Options:[]}} Name:bond0 Mode:active-backup LinksContNs:true Miimon:100 Mtu:0 FailOverMac:1 Links:[map[name:net1] map[name:net2]]}), error: Failed to confirm that link (net1) exists, error: Failed to lookup link name net1, error: Link not found, failed to clean up sandbox container "d5aa4031590678cb0399bde5fa556692257101cd15ca0264d5a87fdbbf2f0c29" network for pod "pod-bond": networkPlugin cni failed to teardown pod "pod-bond_net1" network: delegateDel: error invoking DelegateDel - "bond": error in getting result from DelNetwork: Failed to retrieve link objects from configuration file (&{NetConf:{CNIVersion:0.3.1 Name:bond Type:bond Capabilities:map[] IPAM:{Type:host-local} DNS:{Nameservers:[] Domain: Search:[] Options:[]}} Name:bond0 Mode:active-backup LinksContNs:true Miimon:100 Mtu:0 FailOverMac:1 Links:[map[name:net1] map[name:net2]]}), error: Failed to confirm that link (net1) exists, error: Failed to lookup link name net1, error: Link not found / delegateDel: error invoking DelegateDel - "sriov": error in getting result from DelNetwork: error reading cached NetConf in /var/lib/cni/sriov with name d5aa4031590678cb0399bde5fa556692257101cd15ca0264d5a87fdbbf2f0c29-net2 / delegateDel: error invoking DelegateDel - "sriov": error in getting result from DelNetwork: error reading cached NetConf in /var/lib/cni/sriov with name d5aa4031590678cb0399bde5fa556692257101cd15ca0264d5a87fdbbf2f0c29-net1] Normal AddedInterface 5s multus Add net2 [] from net1/net2 Normal AddedInterface 5s multus Add eth0 [10.20.45.159/32] Normal AddedInterface 5s multus Add net1 [] from net1/net1 Normal AddedInterface 3s multus Add net1 [] from net1/net1 Normal AddedInterface 3s multus Add net2 [] from net1/net2 Normal AddedInterface 3s multus Add eth0 [10.20.45.168/32] Warning FailedCreatePodSandBox 2s (x2 over 4s) kubelet (combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container "f3fb5684ae3bc2277e54bed3f4713e07ab1087b7923ab2bf48554809050d3df8" network for pod "pod-bond": networkPlugin cni failed to set up pod "pod-bond_net1" network: [net1/pod-bond:bond]: error adding container to network "bond": Failed to retrieve link objects from configuration file (&{NetConf:{CNIVersion:0.3.1 Name:bond Type:bond Capabilities:map[] IPAM:{Type:host-local} DNS:{Nameservers:[] Domain: Search:[] Options:[]}} Name:bond0 Mode:active-backup LinksContNs:true Miimon:100 Mtu:0 FailOverMac:1 Links:[map[name:net1] map[name:net2]]}), error: Failed to confirm that link (net1) exists, error: Failed to lookup link name net1, error: Link not found, failed to clean up sandbox container "f3fb5684ae3bc2277e54bed3f4713e07ab1087b7923ab2bf48554809050d3df8" network for pod "pod-bond": networkPlugin cni failed to teardown pod "pod-bond_net1" network: delegateDel: error invoking DelegateDel - "bond": error in getting result from DelNetwork: Failed to retrieve link objects from configuration file (&{NetConf:{CNIVersion:0.3.1 Name:bond Type:bond Capabilities:map[] IPAM:{Type:host-local} DNS:{Nameservers:[] Domain: Search:[] Options:[]}} Name:bond0 Mode:active-backup LinksContNs:true Miimon:100 Mtu:0 FailOverMac:1 Links:[map[name:net1] map[name:net2]]}), error: Failed to confirm that link (net1) exists, error: Failed to lookup link name net1, error: Link not found / delegateDel: error invoking DelegateDel - "sriov": error in getting result from DelNetwork: error reading cached NetConf in /var/lib/cni/sriov with name f3fb5684ae3bc2277e54bed3f4713e07ab1087b7923ab2bf48554809050d3df8-net2 / delegateDel: error invoking DelegateDel - "sriov": error in getting result from DelNetwork: error reading cached NetConf in /var/lib/cni/sriov with name f3fb5684ae3bc2277e54bed3f4713e07ab1087b7923ab2bf48554809050d3df8-net1] Normal AddedInterface 1s multus Add net2 [] from net1/net2 Normal AddedInterface 1s multus Add eth0 [10.20.45.163/32] Normal AddedInterface 1s multus Add net1 [] from net1/net1 Normal SandboxChanged
