ovn availability zone 设计与使用

2023年 8月 22日 52.1k 0

最近想搞下 AZ mesh 来替换 full mesh,从而使得租户的 router 和 subnet的 流表,集中在某个 AZ 内。

AZ 本身是用来划分不同电源下的裸机的。

所以目前需要了解下 ovn 关于 AZ 的设计,以便将租户映射到AZ, 租户下(比如 k8s 的 ns)所有的资源都位于用户绑定的 AZ。 租户的资源也仅只能在其绑定到的 AZ 下(的 node 上)使用。

image.png

采取的方式就是将 AZ 相关的代码整体了解一遍

1. OVN Deployments Interconnection

一个 ovn deployment (ovn 部署集群) 也叫一个 AZ。

AZ == ovn deployment

用户部署多个 ovn 集群是很常见的:

  • 为了在不同的 region, 避免单点故障,一个 AZ 部署一个 ovn 集群
  • 一个 ovn 集群的控制面毕竟存在一个上限

尽管不同 ovn 集群的控制面是彼此独立的,但是不同 AZ 内的负载确实存在 互通 的需求。

OVN interconnection 提供了一种原生的方式来 互联(interconnection) 不同的 AZ。

利用不同 AZ 的 logical router 的 L3 路由通过 overlay 网络。

AZ 是通过 ovn-ic 注册的。

2. ovn-ic-nb 的 Transit_Switch 表

在该模块中,新增了一个 Transit logical switch 表 。
该表中的每一条记录,都代表不同的 ovn deployment (AZ) 间的一个 interconnection 的一个 transit logical switch。

3. ovn-ic-sb

该 ovn-ic-sb 数据库保存了用于连接不同 ovn deployment (AZ) 的配置和状态。数据库的内容由每个 ovn deployment (AZ) 中的ovn-ic程序填充和使用,不应该由 CMS 或用户直接使用。

该数据库由各 ovn deployment (AZ) 中的 ovn-ic 程序共享。它包含来自所有相关 ovn deployment (AZ) 的互连信息,并用作每个 ovn deployment (AZ) 交换信息的中间存储。每个部署中的 ovn-ic 程序负责在这个数据库和它自己的北向和南向数据库之间同步数据。

  

The , ,

tables are the availability zone specific tables.
这些表都是 AZ 的专用表
这些表包含特定于可用区的对象。每个对象由一个可用区拥有和填充,并由其他可用区读取。

3.1 Availability_Zone 表

Each row in this table represents an Availability Zone. Each OVN deployment is considered an availability zone from OVN control plane perspective, with its own central components, such as northbound and southbound databases and ovn-northd daemon.

该表中的每一行记录代表一个可用分区。从 OVN 控制平面的角度来看,每个 OVN deployment 都被视为一个可用性区域(AZ),具有自己的中心组件,例如北向和南向数据库以及 ovn-northd。

3.2 Gateway 表

每一行都代表一个 AZ 内的 interconnection gateway chassis

3.2 Port_Binding 表

该表中的每一行都将 transit switch 上的一个逻辑端口绑定到一个物理网关和一个隧道密钥。交换机的每个端口属于一个 AZ。

4. 版本 22.12

Release 22.12: 为 OVN 对接 南向DB 表路由添加 以下 index:
transit_switch, availability_zone, route_table, ip_prefix, nexthop。

如果该表中有重复的记录,建议用户首先升级所有可用区中的 ovn-ic 守护进程,然后转换 OVS 模式(重启 ovn-ic 数据库守护进程)。

5. 文档

ovn az 相关教程位于: ovn/Documentation/tutorials/ovn-interconnection.rst

本文档提供了多个 ovn deployment (AZ) 基于 OVN 管理的隧道互通的指南。关于 OVN 互连设计的更多细节可以在 ovn-architecture(7) 手册中找到。
文章示例假设设置了两个或多个 ovn deployment (AZ) 并正常运行,可能在不同的数据中心,并且每个 OVN 的网关 Chassis 的 IP 地址彼此可达。

5.1 Setup Interconnection Databases(启动互联数据库)

为了实现不同 ovn 的对接(互联),需要创建 global OVSDB databases,用于存储对接数据。数据库可以设置在可以从每个 OVN部署(AZ) 的所有中心节点访问的到的任何节点上。建议使用 HA 模式设置全局数据库,使用节点不同的可用性区域,以避免单点故障。

  • 装包
  • 启动 icnb icsb 数据库

   # On each global database node ::

    $ ovn-ctl [options] start_ic_ovsdb

  # Options depends on the HA mode you use.  To start standalone mode with TCP
   connections, use ::

    $ ovn-ctl --db-ic-nb-create-insecure-remote=yes 
              --db-ic-sb-create-insecure-remote=yes start_ic_ovsdb

  # This command starts IC database servers that accept both unix socket and
  # TCP connections.  For other modes, see more details with ::

    $ ovn-ctl --help


5.2 Register OVN to Interconnection Databases(在互联数据库中注册 OVN AZ)

每一个 ovn 部署(集群),都要配置一个全局唯一的 AZ 名。


# For each OVN deployment, set an availability zone name ::
    $ ovn-nbctl set NB_Global . name=

# The name should be unique across all OVN deployments, e.g. ovn-east, ovn-west, etc.
# For each OVN deployment, start the ``ovn-ic`` daemon on central nodes ::

    $ ovn-ctl --ovn-ic-nb-db= --ovn-ic-sb-db= 
              --ovn-northd-nb-db= --ovn-northd-sb-db= [more options] start_ic

# An example of ```` is ``tcp::6645``, 
# or for clustered DB: ``tcp::6645,tcp::6645,tcp::6645``.
# ```` is similar, but usually with a different port number, typically, 6646.
# For ```` and ````, use same connection methods as for starting ``northd``.

# Verify each OVN registration from global IC-SB database, using``ovn-ic-sbctl``, 
# either on a global DB node or other nodes but with property
# DB connection method specified in options ::

    $ ovn-ic-sbctl show

5.3 Configure Gateways

对于每个 OVN 部署(AZ),指定一些 chassis 作为互联网关。您需要的网关数量取决于 OVN 部署之间的流量所需的规模和带宽。

节点要作为互联网关,必须首先安装并配置为普通 OVN chassis ,运行 OVS 和 ovn-controller。要将 chassis 设置为互联网关,只需在 chassis 上执行此命令:


    $ ovs-vsctl set open_vswitch . external_ids:ovn-is-interconn=true

# After configuring gateways, verify from the global IC-SB database ::

    $ ovn-ic-sbctl show

5.4 Create Transit Logical Switches

传输逻辑交换机或传输交换机是用于连接不同 OVN AZ 中的逻辑路由器的虚拟交换机。


# create transit switch

    $ ovn-ic-nbctl ts-add 
    

# After creating a transit switch, it can be seen from each OVN deployment's
Northbound database, which can be seen using ::

# 一旦创建之后,所有互联的 ovn AZ 都可以看到

    $ ovn-nbctl find logical_switch other_config:interconn-ts=

# You will also see it with simply 

ovn-nbctl ls-list

If there are multiple tenants that require traffic being isolated from each
other, then multiple transit switches can be created accordingly.

如果有多个租户需要将流量相互隔离,则可以相应地创建多个传输交换机。

5.5 Connect Logical Routers to Transit Switches

将逻辑路由器连接到传输交换机

将每个 OVN 部署(AZ)中的逻辑路由器连接到所需的传输交换机,就像它们是常规逻辑交换机一样,这包括以下步骤:

对于每个 OVN AZ,针对您想要连接的每个逻辑路由器。



# Assume a transit switch named ``ts1`` is already created in ``IC-NB`` 
# and a logical router ``lr1`` created in current OVN deployment.

# 1. Create a logical router port. ::

    $ ovn-nbctl lrp-add lr1 lrp-lr1-ts1 aa:aa:aa:aa:aa:01 169.254.100.1/24

   (The mac and IP are examples.)

# 2. Create a logical switch port on the transit switch and peer with the logical router port. ::

    $ ovn-nbctl lsp-add ts1 lsp-ts1-lr1 -- 
            lsp-set-addresses lsp-ts1-lr1 router -- 
            lsp-set-type lsp-ts1-lr1 router -- 
            lsp-set-options lsp-ts1-lr1 router-port=lrp-lr1-ts1

# 3. Assign gateway(s) for the logical router port. ::

    $ ovn-nbctl lrp-set-gateway-chassis lrp-lr1-ts1  [priority]

# Optionally, you can assign more gateways and specify priorities, to achieve HA, just as usual for a distributed gateway port.

# 当然可以使用多个分布式网关端口(配置不同的优先级)来保证 HA

# Similarly in another OVN deployment, you can connect a logical router (e.g.lr2) to the same transit switch the same way, with a different IP (e.g.169.254.100.2) on the same subnet.
# 其他的 OVN AZ 的 lr ts lsp lrp 也都是同样的操作,只要 gw ip 不同即可

# The ports connected to transit switches will be automatically populated to ``IC-SB`` database, which can be verified by ::
# 连接到 ts 的虚拟交换机会自动同步到 ic-sb

    $ ovn-ic-sbctl show

5.6 Create Static Routes

配置静态路由以便知道互通的两个 AZ 的往来流量

现在您已经准备好了所有的物理和逻辑拓扑,只需在 OVN 部署(AZ)之间创建静态路由,这样数据包就可以由逻辑路由器通过传输交换机转发到远端 OVN(AZ)。

比如:

  • ovn-east, 负载所在路由器为 lr1, 网段为 10.0.1.0/24
  • ovn-west, 负载所在路由器为 lr2, 网段为 10.0.2.0/24

那么静态路由为:


In ovn-east, add below route ::

    $ ovn-nbctl lr-route-add lr1 10.0.2.0/24 169.254.100.2

In ovn-west, add below route ::

    $ ovn-nbctl lr-route-add lr2 10.0.1.0/24 169.254.100.1

Now the traffic should be able to go through between the workloads through
tunnels crossing gateway nodes of ovn-east and ovn-west.
配好路由之后,那么东西两个 ovn AZ 内的负载的流量就可以经过隧道通过网关节点互通

5.7 Route Advertisement (路由通告)

Alternatively, you can avoid the above manual static route configuration by
enabling route advertisement and learning on each OVN deployment

或者,您可以通过在每个 OVN部署(AZ) 内启用路由发布和学习来避免上述手动静态路由配置


    $ ovn-nbctl set NB_Global . options:ic-route-adv=true 
                                options:ic-route-learn=true

# With this setting, the above routes will be automatically learned and configured in Northbound DB in each deployment.  
# For example, in ovn-east, you will see the route ::

    $ ovn-nbctl lr-route-list lr1
    IPv4 Routes
                 10.0.2.0/24             169.254.100.2 dst-ip (learned)

# In ovn-west you will see ::

    $ ovn-nbctl lr-route-list lr2
    IPv4 Routes
                 10.0.1.0/24             169.254.100.1 dst-ip (learned)

Static routes configured in the routers can be advertised and learned as well.
For more details of router advertisement and its configure options, please
see ovn-nb(5).

启用之后,router 上配的静态路由也会被广播并且可以被学习到

6. 测试用例

image.png

想要知道怎么用,首先应该熟悉下测试用例

ovn/tests/ovn-ic-sbctl.at


AT_BANNER([ovn-ic-sbctl])

# OVN_IC_SBCTL_TEST_START
m4_define([OVN_IC_SBCTL_TEST_START],
  [dnl Create database (ovn-ic-sb).  # 创建数据库
   AT_KEYWORDS([ic_sbctl])
   AT_CHECK([ovsdb-tool create ovn-ic-sb.db $abs_top_srcdir/ovn-ic-sb.ovsschema]) # 创建数据库

   dnl Start ovsdb-servers. # 基于 db,启动服务
   AT_CHECK([ovsdb-server --detach --no-chdir --pidfile=ovn_ic_sb_db.pid --unixctl=$OVS_RUNDIR/ovn_ic_sb_db.ctl --log-file=ovsdb_ic_nb.log --remote=punix:$OVS_RUNDIR/ovn_ic_sb_db.sock ovn-ic-sb.db ], [0], [], [stderr])
   on_exit "kill `cat ovn_ic_sb_db.pid`" # 关闭服务
   AT_CHECK([[sed < stderr '
/vlog|INFO|opened log file/d
/ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
   AT_CAPTURE_FILE([ovsdb-server.log])
])

# OVN_IC_SBCTL_TEST_STOP
m4_define([OVN_IC_SBCTL_TEST_STOP],
  [AT_CHECK([check_logs "$1"])
   OVS_APP_EXIT_AND_WAIT_BY_TARGET([$OVS_RUNDIR/ovn_ic_sb_db.ctl], [$OVS_RUNDIR/ovn_ic_sb_db.pid])])

dnl ---------------------------------------------------------------------

AT_SETUP([ovn-ic-sbctl])
OVN_IC_SBCTL_TEST_START
# 创建两个 AZ,创建 encap, 以及 port_binding
for az in 1 2; do
  az_uuid=$(ovn-ic-sbctl create availability_zone name=az$az)
  for gw in 1 2; do
    ovn-ic-sbctl --id=@encap create encap type=geneve ip=192.168.0.$az$gw options="csum=true" 
      -- create gateway availability_zone=$az_uuid name=gw$az$gw encap=@encap hostname=host.gw$az$gw
    for pb in 1 2; do
      ovn-ic-sbctl create port_binding logical_port=lp$az$gw$pb transit_switch="ts$pb" 
        address=""aa:aa:aa:aa:0$az:$gw$pb 169.254.$pb.$az$gw/24"" tunnel_key=$az$gw 
        availability_zone=$az_uuid gateway=gw$az$gw
    done
  done
done

# 确认 AZ 的创建结果,需要包含 gw,ts
AT_CHECK([ovn-ic-sbctl show], [0], [dnl
availability-zone az1
    gateway gw11
        hostname: host.gw11
        type: geneve
            ip: 192.168.0.11
        port lp111
            transit switch: ts1
            address: [["aa:aa:aa:aa:01:11 169.254.1.11/24"]]
        port lp112
            transit switch: ts2
            address: [["aa:aa:aa:aa:01:12 169.254.2.11/24"]]
    gateway gw12
        hostname: host.gw12
        type: geneve
            ip: 192.168.0.12
        port lp121
            transit switch: ts1
            address: [["aa:aa:aa:aa:01:21 169.254.1.12/24"]]
        port lp122
            transit switch: ts2
            address: [["aa:aa:aa:aa:01:22 169.254.2.12/24"]]
availability-zone az2
    gateway gw21
        hostname: host.gw21
        type: geneve
            ip: 192.168.0.21
        port lp211
            transit switch: ts1
            address: [["aa:aa:aa:aa:02:11 169.254.1.21/24"]]
        port lp212
            transit switch: ts2
            address: [["aa:aa:aa:aa:02:12 169.254.2.21/24"]]
    gateway gw22
        hostname: host.gw22
        type: geneve
            ip: 192.168.0.22
        port lp221
            transit switch: ts1
            address: [["aa:aa:aa:aa:02:21 169.254.1.22/24"]]
        port lp222
            transit switch: ts2
            address: [["aa:aa:aa:aa:02:22 169.254.2.22/24"]]
])

AT_CHECK([ovn-ic-sbctl show az2], [0], [dnl
availability-zone az2
    gateway gw21
        hostname: host.gw21
        type: geneve
            ip: 192.168.0.21
        port lp211
            transit switch: ts1
            address: [["aa:aa:aa:aa:02:11 169.254.1.21/24"]]
        port lp212
            transit switch: ts2
            address: [["aa:aa:aa:aa:02:12 169.254.2.21/24"]]
    gateway gw22
        hostname: host.gw22
        type: geneve
            ip: 192.168.0.22
        port lp221
            transit switch: ts1
            address: [["aa:aa:aa:aa:02:21 169.254.1.22/24"]]
        port lp222
            transit switch: ts2
            address: [["aa:aa:aa:aa:02:22 169.254.2.22/24"]]
])


OVN_IC_SBCTL_TEST_STOP
AT_CLEANUP


更详细的用例测试在 ovn/tests/ovn-ic.at
包括 ecmp路由实现高可用, 路由自动学习,自动发布

7. 总结

image.png

根据测试用例和代码实现来看,这个功能就是基于 ovn-ic sb nb 实现的一个特性,目的就是为了实现多 AZ 的 ovn 集群。多 AZ 实际上是控制面横向扩展的的一个特性。

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论