[ English | Indonesia | русский ]

为容器添加额外网络

在某些情况下,为某些容器组(或单个容器)添加额外的网络接口可能很有用。例如,这可用于为 Designate 服务应用来自另一个网络的已知固定 IP 地址。我们将基于此示例展示进一步的配置。假设该网络是 10.0.20.0/24,可以通过 br-dns 接口访问。

要将具有该网络的新接口添加到 dessignate 容器中,我们需要在 openstack_user_config.yml 中执行几个操作。

注意

您可以在 openstack_user_config 设置参考 部分找到 openstack_user_config.yml 配置的详细示例。

  • cidr_networks 中添加此网络

    cidr_networks:
      container: 172.29.236.0/22
      tunnel: 172.29.240.0/22
      storage: 172.29.244.0/22
      designate: 10.0.20.0/24
    
  • provider_networks 中描述网络

    global_overrides:
      provider_networks:
        - network:
          container_bridge: "br-dns"
          container_type: "veth"
          container_interface: "eth5"
          ip_from_q: "designate"
          type: "veth"
          group_binds:
            - dnsaas_hosts
    
  • 定义容器的覆盖

    注意

    添加网关键将在容器内通过它创建默认路由

    dnsaas_hosts:
      aio1:
        ip: 172.29.236.100
        container_vars:
          container_extra_networks:
            dns_address:
              bridge: br-dns
              interface: eth5
              address: 10.0.20.100
              netmask: 255.255.255.0
              gateway: 10.0.20.1
    

在容器中使用 SR-IOV 接口

对于某些部署,可能需要将设备直接传递到容器,例如,当使用 SR-IOV 时,或者设备无法桥接(例如,使用 IPoIB <https://linuxkernel.org.cn/doc/html/2025.2/infiniband/ipoib.html>

您需要手动将物理接口映射到特定容器。这也假定相同的接口名称存在于所有容器中,并且在 LXC 启动之前是一致且存在的。

以下,作为示例,我们将尝试为存储网络使用 IB 接口,并将它们传递到需要存储连接的容器中。为此,您需要在 openstack_user_config.yml 配置的 provider_networks 中描述连接

global_overrides:
  provider_networks:
    - network:
        container_bridge: "ib1"
        container_type: "phys"
        container_interface: "ib1"
        ip_from_q: "storage"
        type: "raw"
        group_binds:
          - cinder_volume
    - network:
        container_bridge: "ib3"
        container_type: "phys"
        container_interface: "ib3"
        ip_from_q: "storage"
        type: "raw"
        group_binds:
         - glance_api
    - network:
        container_bridge: "ib5"
        container_type: "phys"
        container_interface: "ib5"
        ip_from_q: "storage"
        type: "raw"
        group_binds:
          - gnocchi_api