# Kubernetes CNI Cilium# 时间:20210910-[20:00-22:00]# 主题:Cilium VxLAN Mode# 文档:# 作业:Cilium VxLAN Mode
# FAQ:
Cilium VXLAN环境准备
# 1.安装VxLAN环境:# 1.1.Add Cilium repo:$ helm repo add cilium https://helm.cilium.io/# 1.2:.Generate the Cilium Template:helm template cilium cilium/cilium --version 1.10.3 \ --namespace kube-system \ --set kubeProxyReplacement=strict \ --set k8sServiceHost=REPLACE_WITH_API_SERVER_IP \ --set k8sServicePort=REPLACE_WITH_API_SERVER_PORThelm template cilium cilium/cilium --version 1.10 --namespace kube-system --set kubeProxyReplacement=strict --set k8sServiceHost=192.168.2.21 --set k8sServicePort=6443 > vxlan.yaml在这个vxlan.yaml文件中我们需要修改部分参数,以适配后期的Debug:1.4.1. # If you want to run cilium in debug mode change this value to true debug: "true" debug-verbose: "datapath"1.4.2. # If you want cilium monitor to aggregate tracing for packets, set this level # to "low", "medium", or "maximum". The higher the level, the less packets # that will be seen in monitor output. monitor-aggregation: none1.4.3. # Encapsulation mode for communication between nodes # Possible values: # - disabled # - vxlan (default) # - geneve tunnel: vxlan1.4.4. # wait-bpf-mount makes init container wait until bpf filesystem is mounted wait-bpf-mount: "true"#Mount bpf as a service:cat <<EOF | sudo tee /etc/systemd/system/sys-fs-bpf.mount[Unit]Description=Cilium BPF mountsDocumentation=https://docs.cilium.io/DefaultDependencies=noBefore=local-fs.target umount.targetAfter=swap.target[Mount]What=bpffsWhere=/sys/fs/bpfType=bpfOptions=rw,nosuid,nodev,noexec,relatime,mode=700[Install]WantedBy=multi-user.targetEOFsystemctl enable sys-fs-bpf.mountsystemctl restart sys-fs-bpf.mountmount | grep "/sys/fs/bpf"#none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)1.4.5:cilium status:root@k8s-2:/home/cilium# cilium statusKVStore: Ok DisabledKubernetes: Ok 1.20 (v1.20.5) [linux/amd64]Kubernetes APIs: ["cilium/v2::CiliumClusterwideNetworkPolicy", "cilium/v2::CiliumEndpoint", "cilium/v2::CiliumNetworkPolicy", "cilium/v2::CiliumNode", "core/v1::Namespace", "core/v1::Node", "core/v1::Pods", "core/v1::Service", "discovery/v1beta1::EndpointSlice", "networking.k8s.io/v1::NetworkPolicy"]KubeProxyReplacement: Strict [ens33 192.168.2.22 (Direct Routing)]Cilium: Ok 1.10.3 (v1.10.3-4145278)NodeMonitor: Listening for events on 128 CPUs with 64x4096 of shared memoryCilium health daemon: Ok IPAM: IPv4: 6/254 allocated from 10.0.1.0/24, BandwidthManager: DisabledHost Routing: BPFMasquerading: BPF [ens33] 10.0.1.0/24 [IPv4: Enabled, IPv6: Disabled]Controller Status: 35/35 healthyProxy Status: OK, ip 10.0.1.84, 0 redirects active on ports 10000-20000Hubble: Ok Current/Max Flows: 4095/4095 (100.00%), Flows/s: 23.63 Metrics: DisabledEncryption: DisabledCluster health: 2/2 reachable (2021-09-09T12:47:20Z)root@k8s-2:/home/cilium# # 2.cilium 环境中tc 加载ebpf的信息:root@k8s-2:/home/cilium# bpftool net show xdp:tc: # 这里可以查看到我们环境中的各个接口所加载的eBPF的Program。ens33(2) clsact/ingress bpf_netdev_ens33.o:[from-netdev] id 710ens33(2) clsact/egress bpf_netdev_ens33.o:[to-netdev] id 716cilium_net(4) clsact/ingress bpf_host_cilium_net.o:[to-host] id 704cilium_host(5) clsact/ingress bpf_host.o:[to-host] id 692cilium_host(5) clsact/egress bpf_host.o:[from-host] id 698cilium_vxlan(6) clsact/ingress bpf_overlay.o:[from-overlay] id 637cilium_vxlan(6) clsact/egress bpf_overlay.o:[to-overlay] id 642lxc_health(8) clsact/ingress bpf_lxc.o:[from-container] id 663lxcd01889e694fe(10) clsact/ingress bpf_lxc.o:[from-container] id 657 lxcff60740f8e50(12) clsact/ingress bpf_lxc.o:[from-container] id 665lxcb20467fae4ac(14) clsact/ingress bpf_lxc.o:[from-container] id 661lxc9d9e27623fba(16) clsact/ingress bpf_lxc.o:[from-container] id 658flow_dissector:root@k8s-2:/home/cilium# # 3.jq环境准备:root@k8s-2:/home/cilium# apt-get update Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]Get:3 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [791 kB]Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]Get:6 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]Get:7 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [529 kB]Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1075 kB]Get:9 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [30.1 kB]Get:10 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB] Get:11 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]Get:12 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]Get:13 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1070 kB]Get:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [33.3 kB]Get:15 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1516 kB]Get:16 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [575 kB]Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [6324 B]Get:18 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [2668 B]Fetched 19.1 MB in 6s (3330 kB/s) Reading package lists... Doneroot@k8s-2:/home/cilium# apt-get install jqReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following additional packages will be installed: libjq1 libonig5The following NEW packages will be installed: jq libjq1 libonig50 upgraded, 3 newly installed, 0 to remove and 8 not upgraded.Need to get 313 kB of archives.After this operation, 1062 kB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 libonig5 amd64 6.9.4-1 [142 kB]Get:2 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libjq1 amd64 1.6-1ubuntu0.20.04.1 [121 kB]Get:3 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 jq amd64 1.6-1ubuntu0.20.04.1 [50.2 kB]Fetched 313 kB in 2s (136 kB/s)debconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package libonig5:amd64.(Reading database ... 5525 files and directories currently installed.)Preparing to unpack .../libonig5_6.9.4-1_amd64.deb ...Unpacking libonig5:amd64 (6.9.4-1) ...Selecting previously unselected package libjq1:amd64.Preparing to unpack .../libjq1_1.6-1ubuntu0.20.04.1_amd64.deb ...Unpacking libjq1:amd64 (1.6-1ubuntu0.20.04.1) ...Selecting previously unselected package jq.Preparing to unpack .../jq_1.6-1ubuntu0.20.04.1_amd64.deb ...Unpacking jq (1.6-1ubuntu0.20.04.1) ...Setting up libonig5:amd64 (6.9.4-1) ...Setting up libjq1:amd64 (1.6-1ubuntu0.20.04.1) ...Setting up jq (1.6-1ubuntu0.20.04.1) ...Processing triggers for libc-bin (2.31-0ubuntu9.2) ...# 查看map:bpftool map list --bpffs -j | jq | egrep 'id|sys'# bpftool map list --bpffs -j | jq | egrep 'id|sys' | grep ipcache -B1# bpftool map list --bpffs -j | jq | egrep 'id|sys' | grep lxc -B1 # 分别在不同的host上查询相应的Map信息:# 4.地址信息介绍:[root@k8s-1 ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATEScni-4p44n 1/1 Running 1 14d 10.0.1.100 k8s-2 <none> <none>cni-kq5sq 1/1 Running 1 14d 10.0.0.254 k8s-1 <none> <none>#4.1: pod-k8s-1's:# cni-kq5sq 1/1 Running 1 14d 10.0.0.254 k8s-1 <none> <none>[root@k8s-1 ~]# kubectl exec -ti cni-kq5sq -- ip a HOST IP地址:192.168.2.21 <> c0.a8.02.151: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 9e:03:09:77:7d:b0 brd ff:ff:ff:ff:ff:ff link-netnsid 0 # MAC 地址 inet 10.0.0.254/32 scope global eth0 #IP地址:10.0.0.254 <> 0a.00.00.fe valid_lft forever preferred_lft forever[root@k8s-1 ~]# ip a | grep 12: -A 312: lxc0486be7fa43b@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether b6:3a:d6:e8:f2:49 brd ff:ff:ff:ff:ff:ff link-netnsid 2 #MAC地址: b6:3a:d6:e8:f2:49 <> b6:3a:d6:e8:f2:49 inet6 fe80::b43a:d6ff:fee8:f249/64 scope link valid_lft forever preferred_lft forever[root@k8s-1 ~]# 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:bd:fb:4a brd ff:ff:ff:ff:ff:ff # MAC地址 inet 192.168.2.21/24 brd 192.168.2.255 scope global noprefixroute ens33 # IP地址 valid_lft forever preferred_lft forever inet6 fe80::e222:32bb:f400:f0c3/64 scope link noprefixroute valid_lft forever preferred_lft forever# 4.2: pod-k8s-2's # HOST IP地址:192.168.2.22 <> c0.a8.02.16# cni-4p44n 1/1 Running 1 14d 10.0.1.100 k8s-2 <none> <none>[root@k8s-2 ~]# kubectl exec -it cni-4p44n -- ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:a1:1c:41:a5:0c brd ff:ff:ff:ff:ff:ff link-netnsid 0 #MAC地址 inet 10.0.1.100/32 scope global eth0 #IP地址: 10.0.1.100 <> 0a.00.01.64 valid_lft forever preferred_lft forever[root@k8s-2 ~]# ip a | grep 12: -A 312: lxcaa879877688d@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether ea:db:e8:e3:75:cb brd ff:ff:ff:ff:ff:ff link-netnsid 2 #MAC地址: ea:db:e8:e3:75:cb <> ea:db:e8:e3:75:cb inet6 fe80::e8db:e8ff:fee3:75cb/64 scope link valid_lft forever preferred_lft forever[root@k8s-2 ~]# #4.3:首先在k8s-1节点上查看对应的MAP信息:首先是:ip地址信息:[root@k8s-1 ~]# kubectl -nkube-system exec -it cilium-s6vsd -- bash bpftool map list --bpffs -j | jq | egrep 'id|sys'root@k8s-1:/home/cilium# bpftool map dump id 77 key:40 00 00 00 00 00 00 01 0a 00 00 fe 00 00 00 00 <> 10.0.0.25400 00 00 00 00 00 00 00value:47 69 00 00 00 00 00 00 00 00 00 00 <> 本地地址信息显示为全00--------------------------------------------------------------------key:40 00 00 00 00 00 00 01 0a 00 01 64 00 00 00 00 <> 10.0.1.10000 00 00 00 00 00 00 00value:47 69 00 00 c0 a8 02 16 00 00 00 00 <> 192.168.2.22# 4.4:再查看lxc信息:[veth]:[root@k8s-1 ~]# kubectl -nkube-system exec -it cilium-s6vsd -- bash bpftool map list --bpffs -j | jq | egrep 'id|sys'root@k8s-1:/home/cilium# bpftool map dump id 76root@k8s-1:/home/cilium# bpftool map dump id 76key:0a 00 00 fe 00 00 00 00 00 00 00 00 00 00 00 00 <> 10.0.0.25401 00 00 00value:0c 00 00 00 00 00 c2 0d 00 00 00 00 00 00 00 00 <> c2 0d Policy ID || 0c is the interface index. 9e 03 09 77 7d b0 00 00 b6 3a d6 e8 f2 49 00 00 <> link/ether 9e:03:09:77:7d:b0 brd ff:ff:ff:ff:ff:ff link-netnsid 0 # MAC 地址 <> link/ether b6:3a:d6:e8:f2:49 brd ff:ff:ff:ff:ff:ff link-netnsid 2 #MAC地址: b6:3a:d6:e8:f2:49 <> b6:3a:d6:e8:f2:4900 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00# 4.5:查看Tunnel信息:oot@k8s-1:/home/cilium# bpftool map dump id 80key:0a 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <> 0a 00 01 00 --- 10.0.1.001 00 00 00 value:c0 a8 02 16 00 00 00 00 00 00 00 00 00 00 00 00 <> c0 a8 02 16 --- 192.168.2.2201 00 00 00Found 1 elementroot@k8s-1:/home/cilium#
同节点Pod通信
# env 描述:[root@k8s-2 ~]# kubectl get pods -o wide | grep k8s-2cc 1/1 Running 0 16m 10.0.1.211 k8s-2 <none> <none>cni-dq6rz 1/1 Running 0 17m 10.0.1.73 k8s-2 <none> <none>[root@k8s-2 ~]# 在 5.10 内核以后,Cilium 新增了 eBPF Host-Routing 功能,该功能更加速了 eBPF 数据面性能,新增了 bpf_redirect_peer 和 bpf_redirect_neigh 两个 redirect 方式,bpf_redirect_peer 可以理解成 bpf_redirect 的升级版,其将数据包直接送到 veth pair Pod 里面接口 eth0 上,而不经过宿主机的 lxc 接口,这样实现的好处是少进入一次 cpu backlog queue 队列,该特性引入后,路由模式下,Pod -> Pod 性能接近 Node -> Node 性能,同时 Cilium 数据面路径发生了较大的变化。# https://www.infoq.cn/article/p9vg2g9t49kpvhrckfwu1. 除了 host->Pod 外,所有路径都是经过接口跳着走的,最大变化是不再经过 Kernel 转发处理,也意味着来回流量路径不再经过 kernel 的 Netfilter 框架,kernel tc 等模块,大大提升了转发性能;2.redirect_peer 特性专用于 veth pair 类型接口,因为流量被直接重定向到 Pod 里面的接口,所以在宿主机 lxc 口上无法抓到进入 Pod 的流量,因 tcpdump 抓包点在 tc ingress hook 之前,所以可以抓到出 Pod 未经过 eBPF 处理的流量。我们在HOST NS中抓包:[root@k8s-2 ~]# kubectl exec -it cc -- ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 16:ca:13:c3:7c:8f brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.0.1.211/32 scope global eth0 valid_lft forever preferred_lft forever[root@k8s-2 ~]# kubectl exec -it cni-dq6rz -- ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether e6:73:63:ca:dd:4c brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.0.1.73/32 scope global eth0 valid_lft forever preferred_lft forever[root@k8s-2 ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000 link/ether 00:0c:29:e2:bf:86 brd ff:ff:ff:ff:ff:ff inet 192.168.2.22/24 brd 192.168.2.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::a9cd:74a4:47fc:9fec/64 scope link noprefixroute valid_lft forever preferred_lft forever3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:75:f5:10:87 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever4: cilium_net@cilium_host: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether b2:6e:6f:c8:53:fc brd ff:ff:ff:ff:ff:ff inet6 fe80::b06e:6fff:fec8:53fc/64 scope link valid_lft forever preferred_lft forever5: cilium_host@cilium_net: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 52:9b:a0:7a:60:f9 brd ff:ff:ff:ff:ff:ff inet 10.0.1.123/32 scope link cilium_host valid_lft forever preferred_lft forever inet6 fe80::509b:a0ff:fe7a:60f9/64 scope link valid_lft forever preferred_lft forever7: lxc_health@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether f2:bf:2f:84:81:fb brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet6 fe80::f0bf:2fff:fe84:81fb/64 scope link valid_lft forever preferred_lft forever9: lxc59b348afd5c1@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether c2:63:ff:dd:de:bc brd ff:ff:ff:ff:ff:ff link-netnsid 1 inet6 fe80::c063:ffff:fedd:debc/64 scope link valid_lft forever preferred_lft forever11: lxc23801e340e9a@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 1a:1a:f0:a8:a5:bf brd ff:ff:ff:ff:ff:ff link-netnsid 2 inet6 fe80::181a:f0ff:fea8:a5bf/64 scope link valid_lft forever preferred_lft forever[root@k8s-2 ~]# [root@k8s-2 ~]# kubectl exec -ti cc -- ping 10.0.1.73PING 10.0.1.73 (10.0.1.73): 56 data bytes64 bytes from 10.0.1.73: seq=0 ttl=63 time=0.123 ms^C--- 10.0.1.73 ping statistics ---1 packets transmitted, 1 packets received, 0% packet lossround-trip min/avg/max = 0.123/0.123/0.123 ms[root@k8s-2 ~]# 抓包结果:[root@k8s-2 ~]# tcpdump -ne -i lxc23801e340e9a tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on lxc23801e340e9a, link-type EN10MB (Ethernet), capture size 262144 bytes22:16:16.371807 16:ca:13:c3:7c:8f > 1a:1a:f0:a8:a5:bf, ethertype IPv4 (0x0800), length 98: 10.0.1.211 > 10.0.1.73: ICMP echo request, id 19968, seq 0, length 6422:16:21.607147 16:ca:13:c3:7c:8f > 1a:1a:f0:a8:a5:bf, ethertype ARP (0x0806), length 42: Request who-has 10.0.1.123 tell 10.0.1.211, length 2822:16:21.607205 1a:1a:f0:a8:a5:bf > 16:ca:13:c3:7c:8f, ethertype ARP (0x0806), length 42: Reply 10.0.1.123 is-at 1a:1a:f0:a8:a5:bf, length 28^C3 packets captured3 packets received by filter0 packets dropped by kernel[root@k8s-2 ~]# tcpdump -ne -i lxc59b348afd5c1tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on lxc59b348afd5c1, link-type EN10MB (Ethernet), capture size 262144 bytes22:16:16.371876 e6:73:63:ca:dd:4c > c2:63:ff:dd:de:bc, ethertype IPv4 (0x0800), length 98: 10.0.1.73 > 10.0.1.211: ICMP echo reply, id 19968, seq 0, length 6422:16:21.607134 e6:73:63:ca:dd:4c > c2:63:ff:dd:de:bc, ethertype ARP (0x0806), length 42: Request who-has 10.0.1.123 tell 10.0.1.73, length 2822:16:21.607181 c2:63:ff:dd:de:bc > e6:73:63:ca:dd:4c, ethertype ARP (0x0806), length 42: Reply 10.0.1.123 is-at c2:63:ff:dd:de:bc, length 28# 2.redirect_peer 特性专用于 veth pair 类型接口,因为流量被直接重定向到 Pod 里面的接口,所以在宿主机 lxc 口上无法抓到进入 Pod 的流量,因 tcpdump 抓包点在 tc ingress hook 之前,所以可以抓到出 Pod 未经过 eBPF 处理的流量。# 解释一下这句话所要表达的内容:什么叫做:只能抓到出去的包,而不能抓不到进来的包:tcpdump hook 要比 TC的hook更加靠前一些。就以 10.0.1.211所在Pod为例举例说明:10.0.1.211 对应的eth0@if11 的 if11 形成的veth pair lxc23801e340e9a@if10 此时在lxc23801e340e9a上抓包:可以看到:# 1. 从10.0.1.211 的pod去ping 10.0.1.73[root@k8s-2 ~]# kubectl exec -ti cc -- ping 10.0.1.73PING 10.0.1.73 (10.0.1.73): 56 data bytes64 bytes from 10.0.1.73: seq=0 ttl=63 time=0.123 ms[root@k8s-2 ~]# tcpdump -ne -i lxc23801e340e9a tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on lxc23801e340e9a, link-type EN10MB (Ethernet), capture size 262144 bytes22:16:16.371807 16:ca:13:c3:7c:8f > 1a:1a:f0:a8:a5:bf, ethertype IPv4 (0x0800), length 98: 10.0.1.211 > 10.0.1.73: ICMP echo request, id 19968, seq 0, length 64此时可以看到只有从pod 10.0.1.211 上出来的ICMP Request的数据包,而没有ICMP的Replay。此时:# redirect_peer 特性专用于 veth pair 类型接口,因为流量被直接重定向到 Pod 里面的接口,所以在宿主机 lxc 口上无法抓到进入 Pod 的流量,因 tcpdump 抓包点在 tc ingress hook 之前,所以可以抓到出 Pod 未经过 eBPF 处理的流量。这里需要明确的是:需要弄清楚这个,tcpdump和tc生效的位置。这个对于理解次模型非常重要!!!

不同节点Pod通信
# 0.先看一个cilium monitor -vv 的trace信息:[root@k8s-1 ~]# kubectl exec -it cni-kq5sq -- ping 10.0.1.100PING 10.0.1.100 (10.0.1.100): 56 data bytes64 bytes from 10.0.1.100: seq=0 ttl=63 time=0.977 ms^C--- 10.0.1.100 ping statistics ---1 packets transmitted, 1 packets received, 0% packet lossround-trip min/avg/max = 0.977/0.977/0.977 ms[root@k8s-1 ~]# ####################################################################################################################################################################################################------------------------------------------------------------------------------Ethernet {Contents=[..14..] Payload=[..30..] SrcMAC=9e:03:09:77:7d:b0 DstMAC=ff:ff:ff:ff:ff:ff EthernetType=ARP Length=0} # 1.发ARP请求出去CPU 02: MARK 0x0 FROM 3522 from-endpoint: 42 bytes (42 captured), state newidentity 26951->unknown, orig-ip 0.0.0.0 # 2.使用的identity是26591------------------------------------------------------------------------------CPU 02: MARK 0x0 FROM 3522 DEBUG: 42 bytes, Delivery to ifindex 12 # 3.转发到ifindex 12的接口上Ethernet {Contents=[..14..] Payload=[..30..] SrcMAC=b6:3a:d6:e8:f2:49 DstMAC=9e:03:09:77:7d:b0 EthernetType=ARP Length=0} # 4.获得ARP的Response。Dst的MAC地址------------------------------------------------------------------------------Ethernet {Contents=[..14..] Payload=[..86..] SrcMAC=9e:03:09:77:7d:b0 DstMAC=b6:3a:d6:e8:f2:49 EthernetType=IPv4 Length=0} # 5.完成的SrcMAC和DstMAC地址IPv4 {Contents=[..20..] Payload=[..64..] Version=4 IHL=5 TOS=0 Length=84 Id=62026 Flags=DF FragOffset=0 TTL=64 Protocol=ICMPv4 Checksum=12797 SrcIP=10.0.0.254 DstIP=10.0.1.100 Options=[] Padding=[]}ICMPv4 {Contents=[..8..] Payload=[..56..] TypeCode=EchoRequest Checksum=7898 Id=11008 Seq=0}CPU 02: MARK 0x0 FROM 3522 from-endpoint: 98 bytes (98 captured), state newidentity 26951->unknown, orig-ip 0.0.0.0 # 6.进入pod的veth的lxc接口的from-container TCHOOK.CPU 02: MARK 0x0 FROM 3522 DEBUG: Conntrack lookup 1/2: src=10.0.0.254:11008 dst=10.0.1.100:0 # 7.Conntrack 查询CPU 02: MARK 0x0 FROM 3522 DEBUG: Conntrack lookup 2/2: nexthdr=1 flags=1CPU 02: MARK 0x0 FROM 3522 DEBUG: CT verdict: New, revnat=0 CPU 02: MARK 0x0 FROM 3522 DEBUG: Successfully mapped addr=10.0.1.100 to identity=26951 # 8.Dst IP map到identityCPU 02: MARK 0x0 FROM 3522 DEBUG: Conntrack create: proxy-port=0 revnat=0 src-identity=26951 lb=0.0.0.0 # 9.创建新的conntrackCPU 02: MARK 0x0 FROM 3522 DEBUG: Encapsulating to node 3232236054 (0xc0a80216) from seclabel 26951 # 10.map信息查询以后,Encapsulating到节点(0xc0a80216)-192.168.2.22------------------------------------------------------------------------------Ethernet {Contents=[..14..] Payload=[..86..] SrcMAC=9e:03:09:77:7d:b0 DstMAC=b6:3a:d6:e8:f2:49 EthernetType=IPv4 Length=0}IPv4 {Contents=[..20..] Payload=[..64..] Version=4 IHL=5 TOS=0 Length=84 Id=62026 Flags=DF FragOffset=0 TTL=64 Protocol=ICMPv4 Checksum=12797 SrcIP=10.0.0.254 DstIP=10.0.1.100 Options=[] Padding=[]}ICMPv4 {Contents=[..8..] Payload=[..56..] TypeCode=EchoRequest Checksum=7898 Id=11008 Seq=0}CPU 02: MARK 0x0 FROM 3522 to-overlay: 98 bytes (98 captured), state new, interface cilium_vxlanidentity 26951->unknown, orig-ip 0.0.0.0 # 11.被tail call到cilium_vxlan TC,被to-overlay拦截处理CPU 02: MARK 0x0 FROM 11 DEBUG: Conntrack lookup 1/2: src=192.168.2.21:43558 dst=192.168.2.22:8472 # 12.封装完成VxLAN报文CPU 02: MARK 0x0 FROM 11 DEBUG: Conntrack lookup 2/2: nexthdr=17 flags=1CPU 02: MARK 0x0 FROM 11 DEBUG: CT verdict: New, revnat=0CPU 02: MARK 0x0 FROM 11 DEBUG: Conntrack create: proxy-port=0 revnat=0 src-identity=0 lb=0.0.0.0 # 13.创建新的contrack------------------------------------------------------------------------------Ethernet {Contents=[..14..] Payload=[..118..] SrcMAC=00:0c:29:bd:fb:4a DstMAC=00:0c:29:e2:bf:86 EthernetType=IPv4 Length=0} # 14.k8s-1和k8s-2节点的MAC地址信息IPv4 {Contents=[..20..] Payload=[..98..] Version=4 IHL=5 TOS=0 Length=134 Id=40508 Flags= FragOffset=0 TTL=64 Protocol=UDP Checksum=22191 SrcIP=192.168.2.21 DstIP=192.168.2.22 Options=[] Padding=[]}UDP {Contents=[..8..] Payload=[..90..] SrcPort=43558 DstPort=8472(otv) Length=114 Checksum=0} # 15.payload 信息 Packet has been truncatedCPU 02: MARK 0x0 FROM 11 to-network: 148 bytes (128 captured), state new, orig-ip 0.0.0.0------------------------------------------------------------------------------Ethernet {Contents=[..14..] Payload=[..118..] SrcMAC=00:0c:29:e2:bf:86 DstMAC=00:0c:29:bd:fb:4a EthernetType=IPv4 Length=0} # 16.以下进入收包过程,和封装包过程为逆过程IPv4 {Contents=[..20..] Payload=[..98..] Version=4 IHL=5 TOS=0 Length=134 Id=21873 Flags= FragOffset=0 TTL=64 Protocol=UDP Checksum=40826 SrcIP=192.168.2.22 DstIP=192.168.2.21 Options=[] Padding=[]}UDP {Contents=[..8..] Payload=[..90..] SrcPort=34421 DstPort=8472(otv) Length=114 Checksum=0} Packet has been truncatedCPU 05: MARK 0x0 FROM 11 from-network: 148 bytes (128 captured), state new, interface ens33, orig-ip 0.0.0.0CPU 05: MARK 0x0 FROM 11 DEBUG: Successfully mapped addr=192.168.2.22 to identity=6------------------------------------------------------------------------------Ethernet {Contents=[..14..] Payload=[..86..] SrcMAC=02:a1:1c:41:a5:0c DstMAC=ea:db:e8:e3:75:cb EthernetType=IPv4 Length=0}IPv4 {Contents=[..20..] Payload=[..64..] Version=4 IHL=5 TOS=0 Length=84 Id=39214 Flags= FragOffset=0 TTL=64 Protocol=ICMPv4 Checksum=51993 SrcIP=10.0.1.100 DstIP=10.0.0.254 Options=[] Padding=[]}ICMPv4 {Contents=[..8..] Payload=[..56..] TypeCode=EchoReply Checksum=9946 Id=11008 Seq=0}CPU 05: MARK 0x0 FROM 0 from-overlay: 98 bytes (98 captured), state new, interface cilium_vxlan, orig-ip 0.0.0.0CPU 05: MARK 0x0 FROM 0 DEBUG: Tunnel decap: id=26951 flowlabel=0CPU 05: MARK 0x0 FROM 0 DEBUG: Attempting local delivery for container id 3522 from seclabel 26951CPU 05: MARK 0x0 FROM 3522 DEBUG: Conntrack lookup 1/2: src=10.0.1.100:0 dst=10.0.0.254:11008CPU 05: MARK 0x0 FROM 3522 DEBUG: Conntrack lookup 2/2: nexthdr=1 flags=0CPU 05: MARK 0x0 FROM 3522 DEBUG: CT entry found lifetime=50396, revnat=0CPU 05: MARK 0x0 FROM 3522 DEBUG: CT verdict: Reply, revnat=0------------------------------------------------------------------------------Ethernet {Contents=[..14..] Payload=[..86..] SrcMAC=b6:3a:d6:e8:f2:49 DstMAC=9e:03:09:77:7d:b0 EthernetType=IPv4 Length=0}IPv4 {Contents=[..20..] Payload=[..64..] Version=4 IHL=5 TOS=0 Length=84 Id=39214 Flags= FragOffset=0 TTL=63 Protocol=ICMPv4 Checksum=52249 SrcIP=10.0.1.100 DstIP=10.0.0.254 Options=[] Padding=[]}ICMPv4 {Contents=[..8..] Payload=[..56..] TypeCode=EchoReply Checksum=9946 Id=11008 Seq=0}CPU 05: MARK 0x0 FROM 3522 to-endpoint: 98 bytes (98 captured), state reply, interface lxc0486be7fa43bidentity 26951->26951, orig-ip 10.0.1.100, to endpoint 3522------------------------------------------------------------------------------##################################################################################################################################################################################################### env 介绍:[root@k8s-1 ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATEScni-4p44n 1/1 Running 1 14d 10.0.1.100 k8s-2 <none> <none>cni-kq5sq 1/1 Running 1 14d 10.0.0.254 k8s-1 <none> <none>[root@k8s-1 ~]# # 使用Pod cni-kq5sq ping Pod cni-4p44n.# 首先查看Pod cni-kq5sq的路由信息:[root@k8s-1 ~]# kubectl exec -ti cni-kq5sq bash kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.bash-5.1# route -n Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.0.0.214 0.0.0.0 UG 0 0 0 eth010.0.0.214 0.0.0.0 255.255.255.255 UH 0 0 0 eth0bash-5.1# 但是此时我们知道构造的GW是来自宿主机上的cilium_host的ip地址,但是MAC地址却是对应的veth的lxc的mac地址。# 查看cni-kq5sq 对应的veth的lxc接口:bash-5.1# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 9e:03:09:77:7d:b0 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.0.0.254/32 scope global eth0 valid_lft forever preferred_lft foreverbash-5.1# exitexit[root@k8s-1 ~]# 对应的lxc是12. 12: lxc0486be7fa43b@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether b6:3a:d6:e8:f2:49 brd ff:ff:ff:ff:ff:ff link-netnsid 2 inet6 fe80::b43a:d6ff:fee8:f249/64 scope link valid_lft forever preferred_lft forever# 此时查看该接口上加载的bpf program信息:root@k8s-1:/home/cilium# bpftool net show | grep 12lxc0486be7fa43b(12) clsact/ingress bpf_lxc.o:[from-container] id 659##1.0##################### # 1.BPF 代码都在 Cilium 源代码的 bpf/ 目录中。为避免本文过长,将只贴出核心调用栈。大致调用栈如下:__section("from-container")handle_xgress // bpf/bpf_lxc.c |-validate_ethertype(skb, &proto) |-switch (proto) { case ETH_P_IP: tail_handle_ipv4 // bpf/bpf_lxc.c |-handle_ipv4_from_lxc // bpf/bpf_lxc.c |-if dst is k8s Service | lb4_local() | |-ct_create4 | |-lb4_lookup_backend | |-lb4_xlate | |-policy_can_egress4() | |-if tunnel | encap vxlan | else // direct routing, pass to kernel stack (continue normal routing) | ipv4_l3() // dec TTL, set src/dst MAC | asm_set_seclabel_identity(skb); // set identity to skb |-return TC_ACT_OK; }所做的事情:1.对包进行验证,并提取出 L3 proto(协议类型)。2.如果 L3 proto 是 IPv4,调用 tail_handle_ipv4() 进行处理。3.tail_handle_ipv4() 进一步调用 handle_ipv4_from_lxc(),后者完成: 3.1:Service 负载均衡,即从 Service 的后端 Pod 中选择一个合适的,这里假设选择 NODE2 上的 POD4。 3.2:创建或更新连接跟踪(CT)记录。 3.3:执行 DNAT,将包的 dst_ip 由 ServiceIP 改成 POD4_IP。 3.4:进行容器出向(egress)安全策略验证,这里假设没有安全策略,因此能通过验证。 3.5:对包进行封装,或者通过主机进行路由,本文只看直接路由的情况。在送回协议栈之前,调用 ipv4_l3() 设置 TTL、MAC 地址等:intipv4_l3(struct __ctx_buff *ctx, int l3_off, __u8 *smac, __u8 *dmac, struct iphdr *ip4){ ipv4_dec_ttl(ctx, l3_off, ip4)); if (smac) eth_store_saddr(ctx, smac, 0); eth_store_daddr(ctx, dmac, 0); return CTX_ACT_OK;}以上假设都成立的情况下,BPF 程序最后返回 TC_ACK_OK,这个包就进入内核协议 栈继续处理了
eBPF Packet Processing Egress[k8s-1]
root@k8s-1:/home/cilium# bpftool net show xdp:tc:ens33(2) clsact/ingress bpf_netdev_ens33.o:[from-netdev] id 703ens33(2) clsact/egress bpf_netdev_ens33.o:[to-netdev] id 709cilium_net(4) clsact/ingress bpf_host_cilium_net.o:[to-host] id 697cilium_host(5) clsact/ingress bpf_host.o:[to-host] id 685cilium_host(5) clsact/egress bpf_host.o:[from-host] id 691cilium_vxlan(6) clsact/ingress bpf_overlay.o:[from-overlay] id 637cilium_vxlan(6) clsact/egress bpf_overlay.o:[to-overlay] id 642 # match this tc filterlxc_health(8) clsact/ingress bpf_lxc.o:[from-container] id 657lxcccc40ac18a81(10) clsact/ingress bpf_lxc.o:[from-container] id 663lxc0486be7fa43b(12) clsact/ingress bpf_lxc.o:[from-container] id 659lxc245b8cb25654(14) clsact/ingress bpf_lxc.o:[from-container] id 661flow_dissector:root@k8s-1:/home/cilium# 1.Packet’s header information is passed to the handle_xgress, defined in bpf/bpf_lxc.c, where its Ethertype is checked.2.All IPv4 packets are dispatched to handle_ipv4_from_lxc via an intermediate tail_handle_ipv4 function.3.Most of the packet processing decisions are made inside handle_ipv4_from_lxc. At some point the execution flow reaches this part of the function where destination IP lookup is triggered.4.The lookup_ip4_remote_endpoint function is defined inside bpf/lib/eps.h and uses IPCACHE eBPF map to look up information about a remote endpoint:#define lookup_ip4_remote_endpoint(addr) \ ipcache_lookup4(&IPCACHE_MAP, addr, V4_CACHE_KEY_LEN)ipcache_lookup4(struct bpf_elf_map *map, __be32 addr, __u32 prefix){ struct ipcache_key key = { .lpm_key = { IPCACHE_PREFIX_LEN(prefix), {} }, .family = ENDPOINT_KEY_IPV4, .ip4 = addr, }; key.ip4 &= GET_PREFIX(prefix); return map_lookup_elem(map, &key);}# To simulate a map lookup, we can use bpftool map lookup command and point it at a pinned location of the IPCACHE map. The key is based on the ipcache_key struct with destination IP 10.0.1.100# bpftool map lookup pinned /sys/fs/bpf/tc/globals/cilium_ipcache key hex 40 00 00 00 00 00 00 01 0a 00 01 64 00 00 00 00 00 00 00 00 00 00 00 00root@k8s-1:/home/cilium# bpftool map lookup pinned /sys/fs/bpf/tc/globals/cilium_ipcache key hex 40 00 00 00 00 00 00 01 0a 00 01 64 00 00 00 00 00 00 00 00 00 00 00 00key:40 00 00 00 00 00 00 01 0a 00 01 64 00 00 00 0000 00 00 00 00 00 00 00value:47 69 00 00 c0 a8 02 16 00 00 00 00root@k8s-1:/home/cilium# 从上边的信息我们可以看到:Dst_IP:c0 a8 02 16 --- 192.168.2.221.此时一旦这个OuterIP查询完成,此时就可以进入VxLAN的数据报文封装。2.封装过后的VxLAN数据包,就直接在:https://github.com/cilium/cilium/blob/v1.9.1/bpf/lib/encap.h#L153 的逻辑下redirect到VXLAN的egress的interface上。3.此时在外部网络的交换或是路由下送到Dst_IP:192.168.2.22所在的主机上。完成数据包出域的过程。
eBPF Packet Processing Ingress[k8s-2]
# 此时由刚才转发过来的数据包,此时触发cilium_vxlan(6) clsact/ingress bpf_overlay.o:[from-overlay] id 637 root@k8s-1:/home/cilium# bpftool net show xdp:tc:ens33(2) clsact/ingress bpf_netdev_ens33.o:[from-netdev] id 703ens33(2) clsact/egress bpf_netdev_ens33.o:[to-netdev] id 709cilium_net(4) clsact/ingress bpf_host_cilium_net.o:[to-host] id 697cilium_host(5) clsact/ingress bpf_host.o:[to-host] id 685cilium_host(5) clsact/egress bpf_host.o:[from-host] id 691cilium_vxlan(6) clsact/ingress bpf_overlay.o:[from-overlay] id 637 # match this tc filtercilium_vxlan(6) clsact/egress bpf_overlay.o:[to-overlay] id 642 lxc_health(8) clsact/ingress bpf_lxc.o:[from-container] id 657 lxcccc40ac18a81(10) clsact/ingress bpf_lxc.o:[from-container] id 663lxc0486be7fa43b(12) clsact/ingress bpf_lxc.o:[from-container] id 659lxc245b8cb25654(14) clsact/ingress bpf_lxc.o:[from-container] id 6612.This time it’s the from-overlay program located inside bpf/bpf_overlay.c.3.All IPv4 packets get processed by the handle_ipv4 function. # handle_ipv4 通过handle_ipv4 来处理。4.Inside this function execution flow reaches the point[# 这个point就是lookup_ip4_endpoint#] where another map lookup is triggered. This lookup is needed to identify the local interface that’s supposed to receive this packet and build the correct Ethernet header.5.The lookup_ip4_endpoint function is defined inside bpf/lib/eps.h:# 这个lookup的逻辑是:static __always_inline __maybe_unused struct endpoint_info *__lookup_ip4_endpoint(__u32 ip){ struct endpoint_key key = {}; key.ip4 = ip; key.family = ENDPOINT_KEY_IPV4; return map_lookup_elem(&ENDPOINTS_MAP, &key);}# return map_lookup_elem(&ENDPOINTS_MAP 这里返回。ENDPOINTS_MAP。The ENDPOINTS_MAP is pinned in the file called cilium_lxc which can be found next to the IPCACHE map in /sys/fs/bpf/tc/globals/ directory. The key for the lookup can be built based on the endpoint_key data structure by plugging in values of destination IP (10.0.1.110) and IPv4 address family. The resulting lookup will look similar to this:key:0a 00 01 64 00 00 00 00 00 00 00 00 00 00 00 0001 00 00 00value:0c 00 00 00 00 00 ec 02 00 00 00 00 00 00 00 0002 a1 1c 41 a5 0c 00 00 ea db e8 e3 75 cb 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00# 0a 00 01 64 --- 10.0.1.100# 02 a1 1c 41 a5 0c --- pod's MAC # ea db e8 e3 75 cb --- lxc's MAC # 0c --- interface index# ec 02 --- policy idAt this point the lookup result gets passed to ipv4_local_delivery which does two things:1.1:Populates source and destination MAC addresses and decrements TTL.1.2:Makes a tail-call to another eBPF program identified by the lxc_id.2.The last call is made to the to-container program that passes the packet’s context through ipv4_policy where, finally, it gets redirected the destination veth interface.
Capture The Flow
# env [root@k8s-1 ~]# kubectl exec -it cni-kq5sq -- ping 10.0.1.100PING 10.0.1.100 (10.0.1.100): 56 data bytes64 bytes from 10.0.1.100: seq=0 ttl=63 time=0.977 ms^C--- 10.0.1.100 ping statistics ---1 packets transmitted, 1 packets received, 0% packet lossround-trip min/avg/max = 0.977/0.977/0.977 ms[root@k8s-1 ~]# # k8s-1节点上抓包信息:# 1.1:Pod的eth0抓包信息:[ICMP Request && ICMP Replay][root@k8s-1 ~]# kubectl exec -it cni-kq5sq -- tcpdump -ne -i eth0tcpdump: verbose output suppressed, use -v[v]... for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes07:39:20.666747 9e:03:09:77:7d:b0 > b6:3a:d6:e8:f2:49, ethertype IPv4 (0x0800), length 98: 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 281, length 6407:39:20.667323 b6:3a:d6:e8:f2:49 > 9e:03:09:77:7d:b0, ethertype IPv4 (0x0800), length 98: 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 281, length 64# 这里我们看到Pod中是有来有回的ICMP包的。# 1.2:在Pod对应的veth的lxc上抓包:[root@k8s-1 ~]# tcpdump -ne -i lxc0486be7fa43btcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on lxc0486be7fa43b, link-type EN10MB (Ethernet), capture size 262144 bytes15:41:11.742308 9e:03:09:77:7d:b0 > b6:3a:d6:e8:f2:49, ethertype IPv4 (0x0800), length 98: 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 392, length 6415:41:12.742793 9e:03:09:77:7d:b0 > b6:3a:d6:e8:f2:49, ethertype IPv4 (0x0800), length 98: 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 393, length 64# 这里我们发现此时只有ICMP的Request的包,却没有ICMP的Replay的包,具体原因,请参考同节点Pod通信的原理介绍。# 1.3:在cilium_vxlan上抓包:[root@k8s-1 ~]# tcpdump -ne -i cilium_vxlantcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on cilium_vxlan, link-type EN10MB (Ethernet), capture size 262144 bytes15:43:04.814632 9e:03:09:77:7d:b0 > b6:3a:d6:e8:f2:49, ethertype IPv4 (0x0800), length 98: 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 505, length 6415:43:04.815137 02:a1:1c:41:a5:0c > ea:db:e8:e3:75:cb, ethertype IPv4 (0x0800), length 98: 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 505, length 64# 此时我们可以看到这里ICMP的Request 和 Replay都能抓到。# 1.4:在ens33上抓包:[root@k8s-1 ~]# tcpdump -nne -vv -i ens33 -f udptcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes15:45:37.094936 00:0c:29:bd:fb:4a > 00:0c:29:e2:bf:86, ethertype IPv4 (0x0800), length 148: (tos 0x0, ttl 64, id 58729, offset 0, flags [none], proto UDP (17), length 134) 192.168.2.21.43558 > 192.168.2.22.8472: [no cksum] OTV, flags [I] (0x08), overlay 0, instance 269519e:03:09:77:7d:b0 > b6:3a:d6:e8:f2:49, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 15400, offset 0, flags [DF], proto ICMP (1), length 84) 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 657, length 6415:45:37.095632 00:0c:29:e2:bf:86 > 00:0c:29:bd:fb:4a, ethertype IPv4 (0x0800), length 148: (tos 0x0, ttl 64, id 21023, offset 0, flags [none], proto UDP (17), length 134) 192.168.2.22.34421 > 192.168.2.21.8472: [no cksum] OTV, flags [I] (0x08), overlay 0, instance 2695102:a1:1c:41:a5:0c > ea:db:e8:e3:75:cb, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 50485, offset 0, flags [none], proto ICMP (1), length 84) 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 657, length 64# 此时我们在ens33上抓包可以看到,是一个完整的VxLNA的数据包,且有Request和Replay的消息。# k8s-2上信息:# ens33上抓包:[root@k8s-2 ~]# tcpdump -nne -vv -i ens33 -f udptcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes15:48:15.227744 00:0c:29:bd:fb:4a > 00:0c:29:e2:bf:86, ethertype IPv4 (0x0800), length 148: (tos 0x0, ttl 64, id 7556, offset 0, flags [none], proto UDP (17), length 134) 192.168.2.21.43558 > 192.168.2.22.8472: [no cksum] OTV, flags [I] (0x08), overlay 0, instance 269519e:03:09:77:7d:b0 > b6:3a:d6:e8:f2:49, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 28385, offset 0, flags [DF], proto ICMP (1), length 84) 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 815, length 6415:48:15.227998 00:0c:29:e2:bf:86 > 00:0c:29:bd:fb:4a, ethertype IPv4 (0x0800), length 148: (tos 0x0, ttl 64, id 31689, offset 0, flags [none], proto UDP (17), length 134) 192.168.2.22.34421 > 192.168.2.21.8472: [no cksum] OTV, flags [I] (0x08), overlay 0, instance 2695102:a1:1c:41:a5:0c > ea:db:e8:e3:75:cb, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 62239, offset 0, flags [none], proto ICMP (1), length 84) 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 815, length 64# 在cilium_vxlan上抓包:[root@k8s-2 ~]# tcpdump -ne -i cilium_vxlantcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on cilium_vxlan, link-type EN10MB (Ethernet), capture size 262144 bytes15:48:39.252415 9e:03:09:77:7d:b0 > b6:3a:d6:e8:f2:49, ethertype IPv4 (0x0800), length 98: 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 839, length 6415:48:39.252628 02:a1:1c:41:a5:0c > ea:db:e8:e3:75:cb, ethertype IPv4 (0x0800), length 98: 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 839, length 64# 在Pod的lxc上抓包:[root@k8s-2 ~]# tcpdump -ne -i lxcaa879877688dtcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on lxcaa879877688d, link-type EN10MB (Ethernet), capture size 262144 bytes15:49:27.290525 02:a1:1c:41:a5:0c > ea:db:e8:e3:75:cb, ethertype IPv4 (0x0800), length 98: 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 887, length 6415:49:28.290775 02:a1:1c:41:a5:0c > ea:db:e8:e3:75:cb, ethertype IPv4 (0x0800), length 98: 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 888, length 64# 在Pod中抓包:[root@k8s-2 ~]# kubectl exec -it cni-4p44n -- tcpdump -ne -i eth0tcpdump: verbose output suppressed, use -v[v]... for full protocol decodelistening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes07:50:02.619542 ea:db:e8:e3:75:cb > 02:a1:1c:41:a5:0c, ethertype IPv4 (0x0800), length 98: 10.0.0.254 > 10.0.1.100: ICMP echo request, id 15616, seq 922, length 6407:50:02.619811 02:a1:1c:41:a5:0c > ea:db:e8:e3:75:cb, ethertype IPv4 (0x0800), length 98: 10.0.1.100 > 10.0.0.254: ICMP echo reply, id 15616, seq 922, length 64
