oracle竖列的数据怎么变成一行
282
2022-09-11
Calico IPIP 跨节点通信
当前环境信息
[root@master ]# calicoctl get ippoolNAME CIDR SELECTOR default-ipv4-ippool 10.244.0.0/16 all() [root@master ]# calicoctl get ippool default-ipv4-ippool -o yamlapiVersion: projectcalico.org/v3kind: IPPoolmetadata: creationTimestamp: "2022-05-14T09:21:32Z" name: default-ipv4-ippool resourceVersion: "10306" uid: 89d1b7f3-bacc-4f6b-8409-222fb00a4744spec: allowedUses: - Workload - Tunnel blockSize: 26 cidr: 10.244.0.0/16 ipipMode: Always natOutgoing: true nodeSelector: all() vxlanMode: Never
路由聚合
blockSize: 26虽然,calico 默认限制了每个网段只有 64 的 IP 地址,但是如果一个 node 上超过 64 个地址,还是会继续分配一个 网段。node 节点的出口采用路由聚合的方式,比如, 将 26 位的掩码聚合成 25位,或者 24位的掩码,这样路由的条目就会大大减少。
Always or CrossSubnet
ipipMode: Always
Always:表示跨节点通信一直使用 IPIP 封装CrossSubnet:表示在同一个二层,跨节点通信走本地路由,而跨三层的节点互相通信则会通过 IPIP 封装。
BGP
IPIP 模式需要 BGP 来建立节点间的邻接关系,VXLAN 不需要
[root@master ~]# calicoctl node statusCalico process is running.IPv4 BGP status+--------------+-------------------+-------+----------+-------------+| PEER ADDRESS | PEER TYPE | STATE | SINCE | INFO |+--------------+-------------------+-------+----------+-------------+| 192.168.0.81 | node-to-node mesh | up | 01:19:42 | Established || 192.168.0.82 | node-to-node mesh | up | 01:19:25 | Established |+--------------+-------------------+-------+----------+-------------+IPv6 BGP statusNo IPv6 peers found.
服务器模拟 IPIP 通信
1.开启路由模块
echo 1 > /proc/sys/net/ipv4/ip_forward
2.创建两个名称空间
ip netns add ns1ip netns add ns2
3.创建两对veth-pair
ip link add v1 type veth peer name v1_pip link add v2 type veth peer name v2_pip link set v1 netns ns1ip link set v2 netns ns2
4.分别给两对 veth-pair 配置上 IP 地址
# ip address add 10.10.10.2/24 dev v1_pip address add 10.10.20.2/24 dev v2_pip link set v1_p upip link set v2_p upip netns exec ns1 ip address add 10.10.10.1/24 dev v1ip netns exec ns1 ip link set v1 upip netns exec ns1 ip link set lo upip netns exec ns2 ip address add 10.10.20.1/24 dev v2ip netns exec ns2 ip link set v2 upip netns exec ns2 ip link set lo up
查看配置是否生效
[root@70-tem ]# ifconfig v1_p | grep inet inet 10.10.10.2 netmask 255.255.255.0 broadcast 0.0.0.0[root@70-tem ]# ifconfig v2_p | grep inet inet 10.10.20.2 netmask 255.255.255.0 broadcast 0.0.0.0[root@70-tem ]# ip netns exec ns1 ifconfig | grep inet inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10
5.命名空间添加路由
默认新添加的 ns 里没有出去的路由,所以需要我们添加一下新创建的 Pod 就不会存在这种情况,因为 cni 会默认给我们创建出去的路由
[root@70-tem ~]# ip netns exec ns1 route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 v1
添加 route
ip netns exec ns1 route add -net 10.10.20.0 netmask 255.255.255.0 gateway 10.10.10.2ip netns exec ns2 route add -net 10.10.10.0 netmask 255.255.255.0 gateway 10.10.20.2
查看 route
[root@70-tem ]# ip netns exec ns1 route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface10.10.20.0 10.10.10.2 255.255.255.0 UG 0 0 0 v110.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 v1[root@70-tem ]# ip netns exec ns2 route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface10.10.10.0 10.10.20.2 255.255.255.0 UG 0 0 0 v210.10.20.0 0.0.0.0 255.255.255.0 U 0 0 0 v2
v1 ping v2 测试连通性
[root@70-tem ~]# ip netns exec ns1 ping -c 1 10.10.20.1PING 10.10.20.1 (10.10.20.1) 56(84) bytes of data.64 bytes from 10.10.20.1: icmp_seq=1 ttl=63 time=0.048 ms--- 10.10.20.1 ping statistics ---1 packets transmitted, 1 received, 0% packet loss, time 0msrtt min/avg/max/mdev = 0.048/0.048/0.048/0.000 ms
6.创建tunl 和 IPIP Mode
在其对应的名称空间创建 tunnel 设备,并设置隧道模式 ipip,然后还需要设置隧道端点,用 remote 和 local 表示,对应的表示隧道外层 IP,用 ip addr xx peer xx 表示
ip netns exec ns1 ip tunnel add tunl1 mode ipip remote 10.10.20.1 local 10.10.10.1ip netns exec ns1 ip link set tunl1 up ip netns exec ns1 ip address add 10.10.100.10 peer 10.10.200.20 dev tunl1ip netns exec ns2 ip tunnel add tunl2 mode ipip remote 10.10.10.1 local 10.10.20.1ip netns exec ns2 ip link set tunl2 up ip netns exec ns2 ip address add 10.10.200.20 peer 10.10.100.10 dev tunl2
查看配置
[root@70-tem ]# ip netns exec ns1 ifconfig tunl1tunl1: flags=209
7.抓包验证
ip netns exec ns1 ping -c 1 10.10.200.20
对tunl设备抓包,查看原始报文
ip netns exec ns1 tcpdump -pne -i tunl1 -w tunl1.cap
tcpdump -pne -i v1_p -w v1_p.cap
Calico IPIP 跨节点通信数据流向图
环境信息
背景
pod1 10.244.42.68 node1 192.168.0.81pod2 10.244.103.67 node2 192.168.0.82pod1 ping pod2
[root@master ]# kubectl get node -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIMEmaster.whale.com Ready control-plane,master 2d1h v1.23.5 192.168.0.80
node 路由表
通过路由表,我们可以发现,192.168.0.0 大网段都是通过的 ens33 网卡通信。
# node1[root@node1 ]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 ens3310.244.42.64 0.0.0.0 255.255.255.192 U 0 0 0 *10.244.42.68 0.0.0.0 255.255.255.255 UH 0 0 0 caliba60dafcd0610.244.103.64 192.168.0.82 255.255.255.192 UG 0 0 0 tunl010.244.152.128 192.168.0.80 255.255.255.192 UG 0 0 0 tunl0172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33# node2[root@node2 ]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 ens3310.244.42.64 192.168.0.81 255.255.255.192 UG 0 0 0 tunl010.244.103.64 0.0.0.0 255.255.255.192 U 0 0 0 *10.244.103.67 0.0.0.0 255.255.255.255 UH 0 0 0 cali01f311984f910.244.152.128 192.168.0.80 255.255.255.192 UG 0 0 0 tunl0172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
任一 node 节点的 ens33 抓包即可
我们采用的是 pod1 ping pod2 ,针对 node1 节点 ens33 网卡进行抓包
kubectl exec -it cni-test-777bbd57c8-n9m7c -- ping -c 1 10.244.103.67
tcpdump -pne -i ens33 -w node1.cap
Raw IP
TUN/TAP/Tunl
TUN 是 Linux 内核提供的特性,一端在内核协议栈,另一端在用户空间,负责对用户空间和内核协议栈进行报文转发,特点是 TUN 是三层通信,只有 IP地址,没有 MAC 地址,比如 Flannel UDP 模式。TAP 也是 Linux 内核提供的特性,所有的 veth-pair 都是二层设备,特点是二层通信,具有 MAC 地址。Tunl 特点也是三层通信,只有 IP 地址,没有 MAC 地址,也是 Raw Data,但是它的两端都在内核空间,并没有在用户空间,这个是和 TUN 设备最大的区别。 TUN 和 tunl 设备不是同一个设备,虽然都是 RAW data,都是三层,但是 calico tunl 的一端并没有在用户空间里,两端都在内核空间,不然 Flannel IPIP 和 Flannel UDP 没有区别。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~