3.2. 为 RHOSO 网络准备 RHOCP


Red Hat OpenStack Services on OpenShift (RHOSO)服务作为 Red Hat OpenShift Container Platform (RHOCP)工作负载运行。您可以使用 NMState Operator 将 worker 节点连接到所需的隔离网络。您可以使用 MetalLB Operator 在隔离的网络上公开内部服务端点。默认情况下,公共服务端点以 RHOCP 路由的形式公开,因为只有路由用于公共端点。

重要

control plane 接口名称必须在所有节点上一致,因为网络清单直接引用 control plane 接口名称。如果 control plane 接口名称不一致,则 RHOSO 环境将无法部署。如果物理接口名称与节点上不一致,您必须创建一个 Linux 绑定,为可由其他网络清单引用的物理接口配置一致的替代名称。

注意

以下流程中的示例使用 IPv4 地址。您可以使用 IPv6 地址而不是 IPv4 地址。双堆栈 IPv4/6 不可用。有关如何配置 IPv6 地址的详情,请参考 RHOCP 网络指南中的以下资源

3.2.1. 使用隔离网络接口准备 RHOCP

创建一个 NodeNetworkConfigurationPolicy (nncp) CR,以便在 RHOCP 集群中每个 worker 节点上为每个隔离网络配置接口。

流程

  1. 在工作站上创建一个 NodeNetworkConfigurationPolicy (nncp) CR 文件,例如 openstack-nncp.yaml
  2. 检索 RHOCP 集群中 worker 节点的名称:

    $ oc get nodes -l node-role.kubernetes.io/worker -o jsonpath="{.items[*].metadata.name}"
    Copy to Clipboard Toggle word wrap
  3. 发现网络配置:

    $ oc get nns/<worker_node> -o yaml | more
    Copy to Clipboard Toggle word wrap
    • <worker_node > 替换为在第 2 步中获取的 worker 节点的名称,如 worker-1。为每个 worker 节点重复此步骤。
  4. nncp CR 文件中,在 RHOCP 集群中每个 worker 节点上为每个隔离网络配置接口。有关必须配置网络隔离的默认物理数据中心网络的信息,请参阅 OpenShift 网络上的默认 Red Hat OpenStack Services

    在以下示例中,nncp CR 为 worker 节点 1 配置 enp6s0 接口,即 osp-enp6s0-worker-1,将带有 IPv4 地址的 VLAN 接口用于网络隔离:

    apiVersion: nmstate.io/v1
    kind: NodeNetworkConfigurationPolicy
    metadata:
      name: osp-enp6s0-worker-1
    spec:
      desiredState:
        interfaces:
        - description: internalapi vlan interface
          ipv4:
            address:
            - ip: 172.17.0.10
              prefix-length: 24
            enabled: true
            dhcp: false
          ipv6:
            enabled: false
          name: internalapi
          state: up
          type: vlan
          vlan:
            base-iface: enp6s0
            id: 20
            reorder-headers: true
        - description: storage vlan interface
          ipv4:
            address:
            - ip: 172.18.0.10
              prefix-length: 24
            enabled: true
            dhcp: false
          ipv6:
            enabled: false
          name: storage
          state: up
          type: vlan
          vlan:
            base-iface: enp6s0
            id: 21
            reorder-headers: true
        - description: tenant vlan interface
          ipv4:
            address:
            - ip: 172.19.0.10
              prefix-length: 24
            enabled: true
            dhcp: false
          ipv6:
            enabled: false
          name: tenant
          state: up
          type: vlan
          vlan:
            base-iface: enp6s0
            id: 22
            reorder-headers: true
        - description: Configuring enp6s0
          ipv4:
            address:
            - ip: 192.168.122.10
              prefix-length: 24
            enabled: true
            dhcp: false
          ipv6:
            enabled: false
          mtu: 1500
          name: enp6s0
          state: up
          type: ethernet
        - description: octavia vlan interface
          name: octavia
          state: up
          type: vlan
          vlan:
            base-iface: enp6s0
            id: 24
            reorder-headers: true
        - bridge:
            options:
              stp:
                enabled: false
            port:
            - name: enp6s0.24
          description: Configuring bridge octbr
          mtu: 1500
          name: octbr
          state: up
          type: linux-bridge
        - description: designate vlan interface
          ipv4:
            address:
            - ip: 172.26.0.10
              prefix-length: "24"
            dhcp: false
            enabled: true
          ipv6:
            enabled: false
          mtu: 1500
          name: designate
          state: up
          type: vlan
          vlan:
            base-iface: enp7s0
            id: "25"
            reorder-headers: true
        - description: designate external vlan interface
          ipv4:
            address:
            - ip: 172.34.0.10
              prefix-length: "24"
            dhcp: false
            enabled: true
          ipv6:
            enabled: false
          mtu: 1500
          name: designateext
          state: up
          type: vlan
          vlan:
            base-iface: enp7s0
            id: "26"
            reorder-headers: true
      nodeSelector:
        kubernetes.io/hostname: worker-1
        node-role.kubernetes.io/worker: ""
    Copy to Clipboard Toggle word wrap
  5. 在集群中创建 nncp CR:

    $ oc apply -f openstack-nncp.yaml
    Copy to Clipboard Toggle word wrap
  6. 验证 nncp CR 是否已创建:

    $ oc get nncp -w
    NAME                        STATUS        REASON
    osp-enp6s0-worker-1   Progressing   ConfigurationProgressing
    osp-enp6s0-worker-1   Progressing   ConfigurationProgressing
    osp-enp6s0-worker-1   Available     SuccessfullyConfigured
    Copy to Clipboard Toggle word wrap

3.2.2. 将服务 pod 附加到隔离的网络

为每个隔离网络创建一个 NetworkAttachmentDefinition (net-attach-def)自定义资源(CR),以将服务 pod 附加到网络。

流程

  1. 在工作站上创建一个 NetworkAttachmentDefinition (net-attach-def) CR 文件,如 openstack-net-attach-def.yaml
  2. NetworkAttachmentDefinition CR 文件中,为每个隔离网络配置 NetworkAttachmentDefinition 资源,以将服务部署 pod 附加到网络。以下示例为以下网络创建一个 NetworkAttachmentDefinition 资源:

    • internalapi存储ctlplane,以及类型为 macvlan 的租户网络。
    • Octavia,类型为 bridge 的负载平衡管理网络。此网络附加连接管理负载均衡器虚拟机(amphorae)和由 OVN 操作器管理的 Open vSwitch pod 的 pod。
    • DNS 服务(指定)在内部使用的指定网络来管理 DNS 服务器。
    • 指定ext 网络,用于提供对 DNS 服务解析器和 DNS 服务器的外部访问。
    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
      name: internalapi
      namespace: openstack
    spec:
      config: |
        {
          "cniVersion": "0.3.1",
          "name": "internalapi",
          "type": "macvlan",
          "master": "internalapi",
          "ipam": {
            "type": "whereabouts",
            "range": "172.17.0.0/24",
            "range_start": "172.17.0.30",
            "range_end": "172.17.0.70"
          }
        }
    ---
    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
      name: ctlplane
      namespace: openstack
    spec:
      config: |
        {
          "cniVersion": "0.3.1",
          "name": "ctlplane",
          "type": "macvlan",
          "master": "enp6s0",
          "ipam": {
            "type": "whereabouts",
            "range": "192.168.122.0/24",
            "range_start": "192.168.122.30",
            "range_end": "192.168.122.70"
          }
        }
    ---
    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
      name: storage
      namespace: openstack
    spec:
      config: |
        {
          "cniVersion": "0.3.1",
          "name": "storage",
          "type": "macvlan",
          "master": "storage",
          "ipam": {
            "type": "whereabouts",
            "range": "172.18.0.0/24",
            "range_start": "172.18.0.30",
            "range_end": "172.18.0.70"
          }
        }
    ---
    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
      name: tenant
      namespace: openstack
    spec:
      config: |
        {
          "cniVersion": "0.3.1",
          "name": "tenant",
          "type": "macvlan",
          "master": "tenant",
          "ipam": {
            "type": "whereabouts",
            "range": "172.19.0.0/24",
            "range_start": "172.19.0.30",
            "range_end": "172.19.0.70"
          }
        }
    ---
    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
      labels:
        osp/net: octavia
      name: octavia
      namespace: openstack
    spec:
      config: |
        {
          "cniVersion": "0.3.1",
          "name": "octavia",
          "type": "bridge",
          "bridge": "octbr",
          "ipam": {
            "type": "whereabouts",
            "range": "172.23.0.0/24",
            "range_start": "172.23.0.30",
            "range_end": "172.23.0.70",
            "routes": [
               {
                 "dst": "172.24.0.0/16",
                 "gw" : "172.23.0.150"
               }
             ]
          }
        }
    ---
    apiVersion: k8s.cni.cncf.io/v1  
    1
    
    kind: NetworkAttachmentDefinition
    metadata:
      name: designate
      namespace: openstack
    spec:
      config: |
        {
          "cniVersion": "0.3.1",
          "name": "designate",
          "type": "macvlan",
          "master": "designate",
          "ipam": {
            "type": "whereabouts",
            "range": "172.26.0.0/16",
            "range_start": "172.26.0.30",
            "range_end": "172.26.0.70",
          }
        }
    ---
    apiVersion: k8s.cni.cncf.io/v1  
    2
    
    kind: NetworkAttachmentDefinition
    metadata:
      name: designateext
      namespace: openstack
    spec:
      config: |
        {
          "cniVersion": "0.3.1",
          "name": "designateext",
          "type": "macvlan",
          "master": "designateext",
          "ipam": {
            "type": "whereabouts",
            "range": "172.34.0.0/16",
            "range_start": "172.34.0.30",
            "range_end": "172.34.0.70",
          }
        }
    Copy to Clipboard Toggle word wrap
    • metadata.namespace :部署服务的命名空间。
    • "master": 与网络关联的节点接口名称,如 nncp CR 中定义的。
    • "IPAM" : 关于 CNI IPAM 插件将 IP 分配给从范围 .30 - .70 中创建的 pod。
    • "range_start" - "range_end" :IP 地址池范围不得与 MetalLB IPAddressPool 范围和 NetConfig allocationRange 重叠。
  3. 在集群中创建 NetworkAttachmentDefinition CR:

    $ oc apply -f openstack-net-attach-def.yaml
    Copy to Clipboard Toggle word wrap
  4. 验证 NetworkAttachmentDefinition CR 是否已创建:

    $ oc get net-attach-def -n openstack
    Copy to Clipboard Toggle word wrap

3.2.3. 为 RHOSO 网络 VIP 准备 RHOCP

Red Hat OpenStack Services on OpenShift (RHOSO)服务作为 Red Hat OpenShift Container Platform (RHOCP)工作负载运行。您必须创建一个 L2Advertisement 资源,以定义如何宣布虚拟 IP (VIP)和 IPAddressPool 资源来配置哪些 IP 可用作 VIP。在第 2 层模式中,一个节点假定将服务公告给本地网络。

流程

  1. 在工作站上创建一个 IPAddressPool CR 文件,例如 openstack-ipaddresspools.yaml
  2. IPAddressPool CR 文件中,在隔离网络上配置 IPAddressPool 资源,以指定 MetalLB 具有授权的 IP 地址范围:

    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata:
      namespace: metallb-system
      name: ctlplane
    spec:
      addresses:
        - 192.168.122.80-192.168.122.90
      autoAssign: true
      avoidBuggyIPs: false
    ---
    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata:
      name: internalapi
      namespace: metallb-system
    spec:
      addresses:
        - 172.17.0.80-172.17.0.90
      autoAssign: true
      avoidBuggyIPs: false
    ---
    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata:
      namespace: metallb-system
      name: storage
    spec:
      addresses:
        - 172.18.0.80-172.18.0.90
      autoAssign: true
      avoidBuggyIPs: false
    ---
    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata:
      namespace: metallb-system
      name: tenant
    spec:
      addresses:
        - 172.19.0.80-172.19.0.90
      autoAssign: true
      avoidBuggyIPs: false
    ---
    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata:
      namespace: metallb-system
      name: designateext
    spec:
      addresses:
        - 172.34.0.80-172.34.0.120
      autoAssign: true
      avoidBuggyIPs: false
    ---
    Copy to Clipboard Toggle word wrap
    • spec.addresses: IPAddressPool 范围不得与 whereabouts IPAM 范围和 NetConfig allocationRange 重叠。

    有关如何配置其他 IPAddressPool 资源参数的详情,请参考 RHOCP 网络指南中的 配置 MetalLB 地址池

  3. 在集群中创建 IPAddressPool CR:

    $ oc apply -f openstack-ipaddresspools.yaml
    Copy to Clipboard Toggle word wrap
  4. 验证 IPAddressPool CR 是否已创建:

    $ oc describe -n metallb-system IPAddressPool
    Copy to Clipboard Toggle word wrap
  5. 在工作站上创建一个 L2Advertisement CR 文件,如 openstack-l2advertisement.yaml
  6. L2Advertisement CR 文件中,配置 L2Advertisement CR,以定义哪些节点向本地网络公告服务。为每个网络创建一个 L2Advertisement 资源。

    在以下示例中,每个 L2Advertisement CR 指定在附加到 VLAN 的接口上宣布从网络地址池请求的 VIP:

    apiVersion: metallb.io/v1beta1
    kind: L2Advertisement
    metadata:
      name: ctlplane
      namespace: metallb-system
    spec:
      ipAddressPools:
      - ctlplane
      interfaces:
      - enp6s0
      nodeSelectors:
      - matchLabels:
          node-role.kubernetes.io/worker: ""
    ---
    apiVersion: metallb.io/v1beta1
    kind: L2Advertisement
    metadata:
      name: internalapi
      namespace: metallb-system
    spec:
      ipAddressPools:
      - internalapi
      interfaces:
      - internalapi
      nodeSelectors:
      - matchLabels:
          node-role.kubernetes.io/worker: ""
    ---
    apiVersion: metallb.io/v1beta1
    kind: L2Advertisement
    metadata:
      name: storage
      namespace: metallb-system
    spec:
      ipAddressPools:
      - storage
      interfaces:
      - storage
      nodeSelectors:
      - matchLabels:
          node-role.kubernetes.io/worker: ""
    ---
    apiVersion: metallb.io/v1beta1
    kind: L2Advertisement
    metadata:
      name: tenant
      namespace: metallb-system
    spec:
      ipAddressPools:
      - tenant
      interfaces:
      - tenant
      nodeSelectors:
      - matchLabels:
          node-role.kubernetes.io/worker: ""
    ---
    apiVersion: metallb.io/v1beta1
    kind: L2Advertisement
    metadata:
      name: designateext
      namespace: metallb-system
    spec:
      ipAddressPools:
      - designateext
      interfaces:
      - designateext
      nodeSelectors:
      - matchLabels:
          node-role.kubernetes.io/worker: ""
    Copy to Clipboard Toggle word wrap
    • spec.interfaces :宣布从 VLAN 地址池请求的 VIP 的接口。

    有关如何配置其他 L2Advertisement 资源参数的详情,请参考 RHOCP 网络指南中的 使用 L2 公告和标签配置 MetalLB

  7. 在集群中创建 L2Advertisement CR:

    $ oc apply -f openstack-l2advertisement.yaml
    Copy to Clipboard Toggle word wrap
  8. 验证 L2Advertisement CR 是否已创建:

    $ oc get -n metallb-system L2Advertisement
    NAME          IPADDRESSPOOLS    IPADDRESSPOOL SELECTORS   INTERFACES
    ctlplane      ["ctlplane"]                                ["enp6s0"]
    designateext  ["designateext"]                            ["designateext"]
    internalapi   ["internalapi"]                             ["internalapi"]
    storage       ["storage"]                                 ["storage"]
    tenant        ["tenant"]                                  ["tenant"]
    Copy to Clipboard Toggle word wrap
  9. 如果您的集群将 OVNKubernetes 用作网络后端,则必须启用全局转发,以便 MetalLB 可以在二级网络接口中工作。

    1. 检查集群使用的网络后端:

      $ oc get network.operator cluster --output=jsonpath='{.spec.defaultNetwork.type}'
      Copy to Clipboard Toggle word wrap
    2. 如果后端是 OVNKubernetes,则运行以下命令来启用全局 IP 转发:

      $ oc patch network.operator cluster -p '{"spec":{"defaultNetwork":{"ovnKubernetesConfig":{"gatewayConfig":{"ipForwarding": "Global"}}}}}' --type=merge
      Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat