第 2 章 在 OpenShift 上为 Red Hat OpenStack Services 自定义网络


您可以将路由添加到 Red Hat OpenShift Container Platform (RHOCP)网络配置中,您可以在 RHOCP 集群上为 Red Hat OpenStack Services (RHOSO)环境做好准备。

2.1. 在 RHOCP 网络中添加路由

要为 Red Hat OpenShift Container Platform (RHOCP)网络添加路由,您可以在 NodeNetworkConfigurationPolicy (nncp)、NetworkAttachmentDefinition (net-attach-def)和 NetConfig 自定义资源中添加 routes 字段。

先决条件

流程

  1. 在工作站上打开 NodeNetworkConfigurationPolicy (nncp) CR 文件,例如 openstack-nncp.yaml
  2. routes 字段添加到 nncp CR 中,并添加每个路由的配置。以下示例为 nncp CR 添加路由,为 worker 节点 1, osp- enp6s0 -worker-1 配置 enp6s0 接口:

    apiVersion: nmstate.io/v1
    kind: NodeNetworkConfigurationPolicy
    metadata:
      name: osp-enp6s0-worker-1
    spec:
      desiredState:
        interfaces:
          ...
        routes:
          config:
          - destination: 192.168.123.0/24
            metric: 150
            next-hop-address: 192.168.122.1
            next-hop-interface: ospbr
          - destination: 192.168.124.0/24
            metric: 150
            next-hop-address: 192.168.122.1
            next-hop-interface: ospbr
          - destination: 172.17.1.0/24
            metric: 150
            next-hop-address: 172.17.0.1
            next-hop-interface: internalapi
          - destination: 172.17.2.0/24
            metric: 150
            next-hop-address: 172.17.0.1
            next-hop-interface: internalapi
          - destination: 172.18.1.0/24
  3. 更新集群中的 nncp CR:

    $ oc apply -f openstack-nncp.yaml
  4. 在工作站上打开 NetworkAttachmentDefinition (net-attach-def) CR 文件,例如 o'penstack-net-attach-def.yaml'。
  5. routes 字段添加到每个隔离的网络的 config 字段中,再为每个路由添加配置。以下示例 将路由添加到租户网络的 net-attach-def CR 中:

    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",
            "routes": [
              {
                "dst": "172.19.1.0/24",
                "gw": "172.19.0.1"
              },
              {
                "dst": "172.19.2.0/24",
                "gw": "172.19.0.1"
              }
            ]
          }
        }
  6. 更新集群中的 NetworkAttachmentDefinition CR:

    $ oc apply -f openstack-net-attach-def.yaml
  7. 在工作站上打开 NetConfig CR 文件,如 openstack_netconfig.yaml
  8. routes 字段添加到每个隔离的网络的 networks 字段中。以下示例 将路由添加到 ctlplane 网络的三个子网中:

    apiVersion: network.openstack.org/v1beta1
    kind: NetConfig
    metadata:
      name: openstacknetconfig
      namespace: openstack
    spec:
      networks:
      - name: ctlplane
        dnsDomain: ctlplane.openstack.lab
        subnets:
        - name: subnet1
          allocationRanges:
          - end: 192.168.122.120
            start: 192.168.122.100
          - end: 192.168.122.200
            start: 192.168.122.150
          cidr: 192.168.122.0/24
          gateway: 192.168.122.1
          routes:
          - destination: 192.168.123.0/24
            nexthop: 192.168.122.1
          - destination: 192.168.124.0/24
            nexthop: 192.168.122.1
        - name: subnet2
          allocationRanges:
          - end: 192.168.123.120
            start: 192.168.123.100
          - end: 192.168.123.200
            start: 192.168.123.150
          cidr: 192.168.123.0/24
          gateway: 192.168.123.1
          routes:
          - destination: 192.168.122.0/24
            nexthop: 192.168.123.1
          - destination: 192.168.124.0/24
            nexthop: 192.168.123.1
        - name: subnet3
          allocationRanges:
          - end: 192.168.124.120
            start: 192.168.124.100
          - end: 192.168.124.200
            start: 192.168.124.150
          cidr: 192.168.124.0/24
          gateway: 192.168.124.1
          routes:
          - destination: 192.168.122.0/24
            nexthop: 192.168.124.1
          - destination: 192.168.123.0/24
            nexthop: 192.168.124.1
  9. 更新 data plane 网络:

    $ oc apply -f openstack_netconfig.yaml -n openstack
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部