IPVS direct routing on top of openstack (by quqi99)

作者:张华 发表于:2023-07-12
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明

IPVS是Linux内核态的一个L4 LB (KTCPVS, Kernel TCP Virtual Server则是L7 LB), IPVS通过在Netfilter框架中的不同位置注册自己的处理函数来捕获数据包,并根据与IPVS相关的信息表对数据包进行处理,按照IPVS规则中定义的不同的包转发模式,对数据包进行不同的转发处理。
IPVS有哪些包转发模式:NAT、IP tunneling和Direct Routing。本文要做的实验是关于Direct Routeing (client -> LB -> backend -> client), 即从backend返回的包直接direct routing至client (若仍由LB转发的叫NAT, 不会对传输层的端口做修改叫tunneling).

实验

拓扑为:
192.168.21.42 jammy-071431-1 LB (VIP: 192.168.21.177)
192.168.21.238 jammy-071431-2 backend
192.168.21.29 jammy-071431-3 client

步骤如下:

1, create a focal ovn test env

./generate-bundle.sh -s focal --name focal --num-compute 3 --ovn --vault --use-stable-charms --run
juju config neutron-api-plugin-ovn dns-servers=10.5.0.15

2, create 3 test VMs

./tools/instance_launch.sh 3 jammy

3, disable port security and firewall on instances ports

openstack port set --no-security-group --disable-port-security 

4, install IPVS on jammy-071431-1 according to the page [1], 192.168.21.177 is VIP.

apt install ipvsadm -y
ip link add eth-vip type dummy
ip link set eth-vip up
ip a add 192.168.21.177/24 dev eth-vip

echo 1 > /proc/sys/net/ipv4/ip_forward

ipvsadm -C
ipvsadm -A -t 192.168.21.177:80 -s rr
ipvsadm -a -t 192.168.21.177:80 -r 192.168.21.238 -g
ipvsadm -l -n
root@jammy-071431-1:~# ipvsadm -l -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.21.177:80 rr
-> 192.168.21.238:80 Route 1 0 0

5, install nginx on jammy-071431-2

apt install nginx -y
#tcpdump -nt -i any -p tcp port 80 -v

6, run 'curl ' on jammy-071431-3

curl 192.168.21.177

注:上面如果不想肜nginx的话,也可以改用ncat

#run on backend
ncat -k --listen --sctp -vv -p 80
#run on client
echo "hello world"| ncat --sctp 192.168.21.177 80

另外,上面设置VIP的dummy NIC也可以用下列netplay实现:

# cat /etc/netplan/50-cloud-init.yaml  | grep -v ^#
network:
    ethernets:
        ens2:
            dhcp4: true
            match:
                macaddress: fa:16:3e:8c:83:72
            set-name: ens2
    vlans:
        veth0:
            id: 0
            link: ens2
            addresses: [192.168.177.177/24]            
    version: 2

奇怪的是,昨天上面的实验还好好的,但过了一晚上,今天再来试,居然不work了。但此时客户说他们将整个network上的SG关掉之后问题就解决了。好吧,先这样

其他 - 检查conntrck

都disable port SG了,不应该有conntrack了,确认它

while true; do curl 192.168.21.238; sleep 3; done
conntrack -L |grep '192.168.21' |grep -v 'sport=22'
ovs-appctl dpctl/dump-conntrack |grep '192.168.21' |grep -v 'sport=22'
ovs-dpctl dump-conntrack |grep '192.168.21' |grep -v 'sport=22'
ovs-dpctl dump-flows |grep '192.168.21' |grep -v 'sport=22'

其他 - 查看一个port下的流

ovn-nbctl lsp-get-ls neutron_port_id
ovn-sbctl find Port_Binding logical_port=neutron_port_id
ovn-sbctl dump-flows datapath_id_from_previous_command

Reference

[1] https://zhuanlan.zhihu.com/p/627514565?utm_id=0

你可能感兴趣的:(openstack,openstack,ipvs)