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


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

流程

  1. 在工作站上创建一个 NetworkAttachmentDefinition (net-attach-def) CR 文件,如 openstack-net-attach-def.yaml
  2. NetworkAttachmentDefinition CR 文件中,为每个隔离网络配置 NetworkAttachmentDefinition 资源,以将服务部署 pod 附加到网络。以下示例创建一个 NetworkAttachmentDefinition 资源,它使用带有特定网关配置和其他选项的类型网桥接口:

    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
      labels:
        osp/net: internalapi
        osp/net-attach-def-type: standard
      name: internalapi
      namespace: openstack
    spec:
      config: |
    	{
      	"cniVersion": "0.3.1",
      	"name": "internalapi",
      	"type": "bridge",
      	"isDefaultGateway": true,
      	"isGateway": true,
      	"forceAddress": false,
      	"ipMasq": true,
      	"hairpinMode": true,
      	"bridge": "internalapi",
      	"ipam": {
          "type": "whereabouts",
          "range": "172.17.0.0/24",
          "range_start": "172.17.0.30",
          "range_end": "172.17.0.70",
          "gateway": "172.17.0.1"
        }
      }
    • metadata.namespace :部署服务的命名空间。
    • "name": 与网络关联的节点接口名称,如 nncp CR 中定义的。
    • "ipMasq": 可选字段,当设为 true 时,启用 IP 伪装。如果网关没有 IP 地址,ipMasq 无效。默认值为 false。当 data plane 节点没有所需的路由时,或者 data plane 节点在配置自由范围路由(FRR)前没有连接到 control plane 网络时,设置 "ipMasq": true
    • "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
  4. 验证 NetworkAttachmentDefinition CR 是否已创建:

    $ oc get net-attach-def -n openstack
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部