默认场景 - Open Virtual Network (OVN)

概述

自 2023.1 (Antelope) 版本发布以来,OpenStack-Ansible 默认配置 Open Virtual Network (OVN) 机制驱动程序 (ML2/OVN),而不是 ML2/LXB 或 ML2/OVS。该驱动程序提供了使用 Open vSwitch 部署虚拟网络和路由器的可能性,它取代了传统 ML2/LXB 和 ML2/OVS 架构中基于代理的模型。本文档概述了如何在您的环境中设置它。

先决条件

  • Open vSwitch >= 2.17.0

库存架构

虽然 OVN 本身支持许多不同的配置,但 Neutron 和 networking-ovn 利用特定的功能为基于 OpenStack 的云提供虚拟路由功能。

OpenStack-Ansible 将 OVN 相关的服务和功能分为三组

  • neutron_ovn_northd

  • neutron_ovn_controller

  • neutron_ovn_gateway

neutron_ovn_northd 组用于指定哪些主机将包含 OVN northd 守护进程,该守护进程负责将高级 OVN 配置转换为逻辑配置,供 ovn-controller 等守护进程使用。 此外,这些节点托管 OVN Northbound 和 OVN Southbound 数据库,即 ovsdb-server 服务。 此组的成员通常是托管 Neutron API (neutron-server) 的控制器节点。

neutron_ovn_controller 组用于指定哪些主机将运行 OVN 的本地 ovn-controller 守护进程,该守护进程将本地 chassis 和 VIF 注册到 OVN Southbound 数据库,并将逻辑流转换为本地 hypervisor 节点上的物理流。 此组的成员通常是托管虚拟机实例 (nova-compute) 的计算节点。

neutron_ovn_gateway 组用于指定哪些主机有资格充当 OVN Gateway Chassis,该节点是运行 ovn-controller 且能够为租户流量提供外部(南北)连接的节点。 这本质上是能够托管执行 SNAT 和 DNAT(Floating IP)转换的逻辑路由器的节点。东西向流量不受 gateway chassis 的限制,并在 OVN chassis 节点之间执行。

在规划您的架构时,重要的是尽早确定您是希望将 OVN gateway chassis 功能集中到一部分节点还是跨所有计算节点。 将南北路由集中到一组专用网络或 gateway 节点类似于传统的网络节点模型。 启用所有计算节点作为 gateway chassis 将缩小故障域和潜在瓶颈,但代价是确保计算节点可以连接到提供商网络。

下一节将介绍如何配置您的库存以满足某些部署场景。

部署场景

OpenStack-Ansible 支持以下常见部署场景

  • Collapsed Network/Gateway 节点

  • Collapsed Compute/Gateway 节点

  • Standalone Gateway 节点

在 OpenStack-Ansible 部署中,基础设施主机旨在运行 OVN northd 相关服务,而计算主机旨在运行 OVN controller 相关服务。

openstack_user_config.yml 中,指定将运行 ovn-northd 服务的 host 或别名,如下所示

network-northd_hosts:
  infra01:
    ip: 172.25.1.11
  infra02:
    ip: 172.25.1.12
  infra03:
    ip: 172.25.1.13

或者,可以指定别名,如下所示

network-northd_hosts: *infrastructure_hosts

部署者需要通过在 openstack_user_config.yml 中的 network-gateway_hosts 库存组中确定哪些节点被视为“OVN Gateway Chassis”节点。

openstack_user_config.yml 中,指定将运行 ovn-controller 服务并充当 OVN Gateway Chassis 的 host 或别名,如下所示

network-gateway_hosts:
  network-node1:
    ip: 172.25.1.21
  network-node2:
    ip: 172.25.1.22
  network-node3:
    ip: 172.25.1.23

也可以使用现有的库存别名。 在以下示例中,infrastructure_hosts 组的成员也是网络 host,并将充当 OVN Gateway Chassis 节点

network-gateway_hosts: *infrastructure_hosts

在以下示例中,运行 ovn-controller 服务的 compute_hosts 组的成员也将充当 OVN Gateway Chassis 节点

network-gateway_hosts: *compute_hosts

最后,也可以针对特定的 host

network-gateway_hosts:
  compute5:
    ip: 172.25.1.55
  compute10:
    ip: 172.25.1.60
  compute15:
    ip: 172.25.1.65
  compute20:
    ip: 172.25.1.70
  compute25:
    ip: 172.25.1.75

OpenStack-Ansible 用户变量

要使用 ML2/OVN 机制驱动程序部署 OpenStack-Ansible,请在 `/etc/openstack_deploy/user_variables.yml` 文件中设置以下用户变量

neutron_plugin_type: ml2.ovn

neutron_plugin_base:
  - ovn-router

neutron_ml2_drivers_type: "vlan,local,geneve,flat"

这些覆盖指示 Ansible 部署 OVN 机制驱动程序和相关的 OVN 组件。 这是通过将 neutron_plugin_type 设置为 ml2.ovn 来完成的。

neutron_plugin_base 覆盖启用 Neutron 使用 OVN 进行路由功能。

neutron_ml2_drivers_type 覆盖提供对 OVN 支持的所有类型驱动程序的支持。

提供程序网络覆盖可以在全局或每 host 的基础上指定,并且可以使用以下格式在 user_variables.yml 或每 host 的 openstack_user_config.yml 或 host 变量中使用。

注意

当定义 network_interface_mappings 时,playbooks 将尝试将映射的接口连接到相应的 OVS bridge。 省略 network_interface_mappings 将要求操作员使用 ovs-vsctl add-port 命令手动将接口连接到 bridge。

# When configuring Neutron to support geneve tenant networks and
# vlan provider networks the configuration may resemble the following:
neutron_provider_networks:
  network_types: "geneve"
  network_geneve_ranges: "1:1000"
  network_vlan_ranges: "public"
  network_mappings: "public:br-publicnet"
  network_interface_mappings: "br-publicnet:bond1"

# When configuring Neutron to support only vlan tenant networks and
# vlan provider networks the configuration may resemble the following:
neutron_provider_networks:
  network_types: "vlan"
  network_vlan_ranges: "public:203:203,467:500"
  network_mappings: "public:br-publicnet"
  network_interface_mappings: "br-publicnet:bond1"

# When configuring Neutron to support multiple vlan provider networks
# the configuration may resemble the following:
neutron_provider_networks:
  network_types: "vlan"
  network_vlan_ranges: "public:203:203,467:500,private:101:200,301:400"
  network_mappings: "public:br-publicnet,private:br-privatenet"
  network_interface_mappings: "br-publicnet:bond1,br-privatenet:bond2"

(可选) DVR 或分布式 L3 路由

如果 ovn / enable_distributed_floating_ip 标志在 neutron 服务器配置中配置为 True,则 DVR 将用于 Floating IPs。

为 neutron 服务器创建组变量文件 /etc/openstack_deploy/group_vars/neutron_server.yml。 它必须包含

# DVR/Distributed L3 routing support
neutron_ovn_distributed_fip: True

有用的 Open Virtual Network (OVN) 命令

以下命令可用于提供有关 Open vSwitch 网络和配置状态的有用信息。

注意

针对 OVN Southbound 和 Northbound 数据库的命令预计将从 neutron_ovn_northd host 运行。 OpenStack-Ansible 会将一个名为 /root/ovnctl.rc 的 openrc 文件放置在这些 host 上。 一旦您 source 该文件,将设置所需的环境变量以连接到数据库。 或者,您可以使用 --no-leader-only 标志连接到本地数据库,而不是默认的 leader 数据库。

可以在上游 OVN 文档和其他此页面上列出的资源中找到其他命令。

检查 NB/SB DB 集群状态

可以执行以下 ad-hoc 命令以查找 NB/SB 数据库的当前状态和 leader

ansible neutron_ovn_northd -m command -a "ovs-appctl -t /var/run/ovn/ovnnb_db.ctl cluster/status OVN_Northbound"
ansible neutron_ovn_northd -m command -a "ovs-appctl -t /var/run/ovn/ovnsb_db.ctl cluster/status OVN_Southbound"

检查 Open vSwitch 的本地状态

ovs-vsctl list open_vswitch 命令提供有关本地 Open vSwitch 数据库中 open_vswitch 表的信息,可以从任何网络或计算 host 运行

root@mnaio-controller1:~# ovs-vsctl list open_vswitch
_uuid               : 7f96baf2-d75e-4a99-bb19-ca7138fc14c2
bridges             : []
cur_cfg             : 1
datapath_types      : [netdev, system]
datapaths           : {}
db_version          : "8.3.0"
dpdk_initialized    : false
dpdk_version        : none
external_ids        : {hostname=mnaio-controller1, rundir="/var/run/openvswitch", system-id="a67926f2-9543-419a-903d-23e2aa308368"}
iface_types         : [bareudp, erspan, geneve, gre, gtpu, internal, ip6erspan, ip6gre, lisp, patch, stt, system, tap, vxlan]
manager_options     : []
next_cfg            : 1
other_config        : {}
ovs_version         : "2.17.2"
ssl                 : []
statistics          : {}
system_type         : ubuntu
system_version      : "20.04"

如果您只想检查 ovs-vsctl 输出中的特定字段,例如应用接口映射,则可以这样选择它

root@mnaio-controller1:~# ovs-vsctl get open . external_ids:ovn-bridge-mappings
"vlan:br-provider"

您还可以通过类似命令获取有关 agent UUID 的信息,该信息将在 openstack network agent list 输出中说明

root@mnaio-controller1:~# ovs-vsctl get open . external_ids:system-id
"a67926f2-9543-419a-903d-23e2aa308368"

从 SouthBound 数据库获取信息

Chassis 详情

ovn-sbctl show 命令提供与 southbound 连接相关的信息。 如果在 ovn_northd 容器外部使用,请指定连接详细信息

root@mnaio-controller1:~# ovn-sbctl show
Chassis "5335c34d-9233-47bd-92f1-fc7503270783"
    hostname: mnaio-compute1
    Encap geneve
        ip: "172.25.1.31"
        options: {csum="true"}
    Encap vxlan
        ip: "172.25.1.31"
        options: {csum="true"}
    Port_Binding "852530b5-1247-4ec2-9c39-8ae0752d2144"
Chassis "ff66288c-5a7c-41fb-ba54-6c781f95a81e"
    hostname: mnaio-compute2
    Encap vxlan
        ip: "172.25.1.32"
        options: {csum="true"}
    Encap geneve
        ip: "172.25.1.32"
        options: {csum="true"}
Chassis "cb6761f4-c14c-41f8-9654-16f3fc7cc7e6"
    hostname: mnaio-compute3
    Encap geneve
        ip: "172.25.1.33"
        options: {csum="true"}
    Encap vxlan
        ip: "172.25.1.33"
        options: {csum="true"}
    Port_Binding cr-lrp-022933b6-fb12-4f40-897f-745761f03186

您可以通过提供 chassis 的 name(其中 name 是 agent 的 UUID(来自 ovs-vsctl 输出的 external_ids:system-id)),获取有关 chassis 的特定信息,例如

root@mnaio-controller1:~# ovn-sbctl list Chassis ff66288c-5a7c-41fb-ba54-6c781f95a81e
_uuid               : b0b6ebec-1c64-417a-adb7-d383632a4c5e
encaps              : [a3ba78c3-df14-4144-81e0-e6379541bc89]
external_ids        : {}
hostname            : mnaio-compute2
name                : "ff66288c-5a7c-41fb-ba54-6c781f95a81e"
nb_cfg              : 0
other_config        : {ct-no-masked-label="true", datapath-type=system, fdb-timestamp="true", iface-types="afxdp,afxdp-nonpmd,bareudp,erspan,geneve,gre,gtpu,internal,ip6erspan,ip6gre,lisp,patch,srv6,stt,system,tap,vxlan", is-interconn="false", mac-binding-timestamp="true", ovn-bridge-mappings="vlan:br-provider", ovn-chassis-mac-mappings="", ovn-cms-options="", ovn-ct-lb-related="true", ovn-enable-lflow-cache="true", ovn-limit-lflow-cache="", ovn-memlimit-lflow-cache-kb="", ovn-monitor-all="false", ovn-trim-limit-lflow-cache="", ovn-trim-timeout-ms="", ovn-trim-wmark-perc-lflow-cache="", port-up-notif="true"}
transport_zones     : []
vtep_logical_switches: []

如您所见,other_config 行也包含 bridge-mapping,可以以类似于 ovs-vsctl 的方式从表中获取它

root@mnaio-controller1:~# ovn-sbctl get Chassis ff66288c-5a7c-41fb-ba54-6c781f95a81e other_config:ovn-bridge-mappings
"vlan:br-provider"

从 NorthBound 数据库获取信息

检查网络和端口

ovn-nbctl show 命令提供有关 OVN 知道的网络、端口和其他对象的信息,并演示了 northbound 数据库与 neutron-server 之间的连接。

root@mnaio-controller1:~# ovn-nbctl show
switch 03dc4558-f83e-4531-b854-156292f1dbad (neutron-a6e65821-93e2-4521-9e31-37c35d52d953) (aka project-tenant-network)
    port 852530b5-1247-4ec2-9c39-8ae0752d2144
        addresses: ["fa:16:3e:d2:af:bf 10.3.3.49"]
    port 624de478-7e75-472f-b867-e6f514790a81
        addresses: ["fa:16:3e:bf:c0:c3 10.3.3.3", "unknown"]
    port 1cca8ef3-d3c9-4307-a779-13348db5e647
        addresses: ["fa:16:3e:4a:67:ed 10.3.3.4", "unknown"]
    port 05e20b32-2933-414a-ba31-eac683d09ac2
        addresses: ["fa:16:3e:bd:5d:e8 10.3.3.5", "unknown"]
    port 5a2e35cb-178b-443b-9f15-4c6ec4db4ac7
        type: router
        router-port: lrp-5a2e35cb-178b-443b-9f15-4c6ec4db4ac7
    port 2d52a2bf-ab37-4a18-87bd-8808a99c67d3
        type: localport
        addresses: ["fa:16:3e:30:b4:a0 10.3.3.2"]
switch 3e03d5f1-4cfe-4c61-bd4c-8a661634d77b (neutron-b0b4017f-a9d1-4923-af35-944b88b7a393) (aka flat-external-provider-network)
    port 022933b6-fb12-4f40-897f-745761f03186
        type: router
        router-port: lrp-022933b6-fb12-4f40-897f-745761f03186
    port 347a7d8d-fd0f-48be-be02-d603258f0a08
        addresses: ["fa:16:3e:f4:6a:17 192.168.25.5", "unknown"]
    port 29c83838-329d-4839-bddb-818c7e2e9bc7
        addresses: ["fa:16:3e:a3:48:a8 192.168.25.3", "unknown"]
    port 173c9ceb-4dd3-4268-aaa3-c7b0f693a557
        type: localport
        addresses: ["fa:16:3e:0c:37:ed 192.168.25.2"]
    port 7a0175fd-ac09-4466-b3d0-26f696e3769c
        addresses: ["fa:16:3e:ad:19:c2 192.168.25.4", "unknown"]
    port provnet-525d3402-d582-49b4-b946-f28de8bbc615
        type: localnet
        addresses: ["unknown"]
router 5ebb0cdb-2026-4454-a32e-eb5425ae7296 (neutron-b0d6ca32-fda3-4fdc-b648-82c8bee303dc) (aka project-router)
    port lrp-5a2e35cb-178b-443b-9f15-4c6ec4db4ac7
        mac: "fa:16:3e:3a:1c:bb"
        networks: ["10.3.3.1/24"]
    port lrp-022933b6-fb12-4f40-897f-745761f03186
        mac: "fa:16:3e:1f:cd:e9"
        networks: ["192.168.25.242/24"]
        gateway chassis: [cb6761f4-c14c-41f8-9654-16f3fc7cc7e6 ff66288c-5a7c-41fb-ba54-6c781f95a81e 5335c34d-9233-47bd-92f1-fc7503270783]
    nat 79d8486c-8b5e-4d6c-a56f-9f0df115f77f
        external ip: "192.168.25.242"
        logical ip: "10.3.3.0/24"
        type: "snat"
    nat d338ccdf-d3c4-404e-b2a5-938d0c212e0d
        external ip: "192.168.25.246"
        logical ip: "10.3.3.49"
        type: "dnat_and_snat"

检查 Floating IPs

Floating IPs 和 Router SNAT 在 NB 数据库中表示为 NAT 规则,其中 FIP 的类型为 dnat_and_snat。 您可以使用 OVN 数据库中格式为 neutron-<UUID> 的路由器名称来获取分配给特定路由器的 NAT 规则列表,其中 UUID 是 Neutron 数据库中的路由器的 UUID。 命令如下所示

注意

请记住,如果外部网络是 geneve 网络并且路由器绑定到 chassis 而不是其外部端口,则对于 dnat_and_snat 规则将不会定义 GATEWAY_PORT。

root@mnaio-controller1:~# ovn-nbctl lr-nat-list neutron-b0d6ca32-fda3-4fdc-b648-82c8bee303dc
TYPE             GATEWAY_PORT          EXTERNAL_IP        EXTERNAL_PORT    LOGICAL_IP          EXTERNAL_MAC         LOGICAL_PORT
dnat_and_snat    lrp-16555e74-fbef-    192.168.25.246                      10.3.3.49
snat                                   192.168.25.242                      10.3.3.0/24

检查和迁移 Logical Router 在 Chassis 之间

当外部网络具有 VLAN 或 FLAT 类型时,路由器到 gateway 节点的映射/位置可以通过该路由器的逻辑端口建立。为此,您需要知道连接到路由器的外部端口的 UUID。 如果主题中的外部网络名为 public,则可以使用以下方法确定 gateway 节点

root@mnaio-controller1:~# openstack port list --router b0d6ca32-fda3-4fdc-b648-82c8bee303dc --network public -c ID
+--------------------------------------+
| ID                                   |
+--------------------------------------+
| 16555e74-fbef-4ecb-918c-2fb76bf5d42d |
+--------------------------------------+
root@mnaio-controller1:~# ovn-nbctl get Logical_Router_Port lrp-16555e74-fbef-4ecb-918c-2fb76bf5d42d status:hosting-chassis
"5335c34d-9233-47bd-92f1-fc7503270783"
root@mnaio-controller1:~# ovn-sbctl get Chassis 5335c34d-9233-47bd-92f1-fc7503270783 hostname
mnaio-compute1
root@mnaio-controller1:~# openstack network agent show 5335c34d-9233-47bd-92f1-fc7503270783 -c host
+-------+-----------------------------+
| Field | Value                       |
+-------+-----------------------------+
| host  | mnaio-compute1              |
+-------+-----------------------------+

要列出逻辑端口计划在其上的所有 gateway chassis 及其优先级,可以使用

root@mnaio-controller1:~# ovn-nbctl lrp-get-gateway-chassis lrp-16555e74-fbef-4ecb-918c-2fb76bf5d42d | cut -d '_' -f 2
5335c34d-9233-47bd-92f1-fc7503270783     2
cb6761f4-c14c-41f8-9654-16f3fc7cc7e6     1

为了将活动的路由器逻辑端口迁移到另一个节点,您可以执行以下命令

root@mnaio-controller1:~# ovn-nbctl lrp-set-gateway-chassis lrp-16555e74-fbef-4ecb-918c-2fb76bf5d42d ff66288c-5a7c-41fb-ba54-6c781f95a81e 10

在 Geneve 网络充当路由器的外部网络时,Logical Router 将固定到 chassis 而不是其 LRP

# ovn-nbctl --no-leader-only get Logical_Router neutron-b0d6ca32-fda3-4fdc-b648-82c8bee303dc options
{always_learn_from_arp_request="false", chassis="5335c34d-9233-47bd-92f1-fc7503270783", dynamic_neigh_routers="true", mac_binding_age_threshold="0"}

此类路由器的所有 LRP 都将保持未绑定状态。

OVN 数据库填充

如果 OVN DB 集群失败并导致数据丢失,则始终可以从 Neutron 数据库中存储的状态重新填充 OVN SB/NB 中的数据。

为此,您可以执行以下操作

root@mnaio-controller1:~# lxc-attach -n $(lxc-ls -1 | grep neutron-server)
root@mnaio-controller1-neutron-server-container-7510c8bf:/# source /etc/openstack-release
root@mnaio-controller1-neutron-server-container-7510c8bf:/# /openstack/venvs/neutron-${DISTRIB_RELEASE}/bin/neutron-ovn-db-sync-util --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini --ovn-neutron_sync_mode repair

neutron-ovn-db-sync-util 命令也用于从 OVS 迁移到 OVN。 为此,您需要提供 --ovn-neutron_sync_mode migrate 而不是上面示例中显示的 repair

说明

ovn-controller 服务将注册为 agent,可以使用 openstack network agent list 命令观察到

+--------------------------------------+------------------------------+-------------------+-------------------+-------+-------+----------------------------+
| ID                                   | Agent Type                   | Host              | Availability Zone | Alive | State | Binary                     |
+--------------------------------------+------------------------------+-------------------+-------------------+-------+-------+----------------------------+
| 5335c34d-9233-47bd-92f1-fc7503270783 | OVN Controller Gateway agent | mnaio-compute1    |                   | :-)   | UP    | ovn-controller             |
| ff66288c-5a7c-41fb-ba54-6c781f95a81e | OVN Controller Gateway agent | mnaio-compute2    |                   | :-)   | UP    | ovn-controller             |
| cb6761f4-c14c-41f8-9654-16f3fc7cc7e6 | OVN Controller Gateway agent | mnaio-compute3    |                   | :-)   | UP    | ovn-controller             |
| 38206799-af64-589b-81b2-405f0cfcd198 | OVN Metadata agent           | mnaio-compute1    |                   | :-)   | UP    | neutron-ovn-metadata-agent |
| 9e9b49c7-dd00-5f58-a3f5-22dd01f562c4 | OVN Metadata agent           | mnaio-compute2    |                   | :-)   | UP    | neutron-ovn-metadata-agent |
| 72b1a6e2-4cca-570f-83a4-c05dcbbcc11f | OVN Metadata agent           | mnaio-compute3    |                   | :-)   | UP    | neutron-ovn-metadata-agent |
+--------------------------------------+------------------------------+-------------------+-------------------+-------+-------+----------------------------+