3.6. 为集群启用 OVS balance-slb 模式
您可以启用 Open vSwitch (OVS) balance-slb 模式,以便两个或多个物理接口共享其网络流量。balance-slb 模式接口可以为运行虚拟化工作负载的集群提供源负载均衡(SLB)功能,而无需与网络交换机协商。
目前,源负载均衡在绑定接口上运行,该接口连接到辅助网桥,如 br-phy。源负载均衡仅在不同的 Media Access Control (MAC)地址和虚拟局域网(VLAN)组合之间平衡。请注意,所有 OVN-Kubernetes pod 流量都使用相同的 MAC 地址和 VLAN,因此此流量无法在多个物理接口负载平衡。
下图显示了简单集群基础架构布局上的 balance-slb 模式。虚拟机(VM)连接到特定的 localnet NetworkAttachmentDefinition (NAD)自定义资源定义(CRD)、NAD 0 或 NAD 1。每个 NAD 均为虚拟机提供对底层物理网络的访问,支持 VLAN 标记或未标记的流量。br-ex OVS 网桥从虚拟机接收流量,并将流量传递到下一个 OVS 网桥 br-phy。br-phy 网桥作为 SLB 绑定的控制器。SLB 绑定通过物理接口链接(如 eno0 和 eno1)平衡来自不同虚拟机端口的流量。此外,来自一个物理接口的入口流量可以通过一组 OVS 网桥来访问虚拟机。
图 3.1. OVS balance-slb 模式在带有两个 NAD CRD 的 localnet 上运行
您可以使用 OVS 绑定将 balance-slb 模式接口集成到主或二级网络类型中。注意关于 OVS 绑定的以下点:
- 支持 OVN-Kubernetes CNI 插件,并轻松与插件集成。
-
原生支持
balance-slb模式。
先决条件
-
将多个物理接口附加到主网络,并在
MachineConfig文件中定义接口。 -
您创建了清单对象,并在对象配置文件中定义了自定义
br-ex网桥。 - 您附加了多个物理接口,并在 NAD CRD 文件中定义接口。
流程
对于集群中的每个裸机主机,在
install-config.yaml文件中为集群定义一个networkConfig部分,如下例所示:apiVersion: v1 kind: InstallConfig metadata: name: <cluster-name> # ... networkConfig: interfaces: - name: enp1s01 type: ethernet state: up ipv4: dhcp: true enabled: true ipv6: enabled: false - name: enp2s02 type: ethernet state: up mtu: 15003 ipv4: dhcp: true enabled: true ipv6: dhcp: true enabled: true - name: enp3s04 type: ethernet state: up mtu: 1500 ipv4: enabled: false ipv6: enabled: false # ...在 NMState 配置文件中定义每个网络接口:
定义许多网络接口的 NMState 配置文件示例
apiVersion: nmstate.io/v1 kind: NodeNetworkConfigurationPolicy metadata: # ... ovn: bridge-mappings: - localnet: localnet-network bridge: br-ex state: present interfaces: - name: br-ex type: ovs-bridge state: up bridge: allow-extra-patch-ports: true port: - name: br-ex - name: patch-ex-to-phy ovs-db: external_ids: bridge-uplink: "patch-ex-to-phy" - name: br-ex type: ovs-interface state: up mtu: 15001 ipv4: enabled: true dhcp: true auto-route-metric: 48 ipv6: enabled: false dhcp: false auto-route-metric: 48 - name: br-phy type: ovs-bridge state: up bridge: allow-extra-patch-ports: true port: - name: patch-phy-to-ex - name: ovs-bond link-aggregation: mode: balance-slb port: - name: enp2s0 - name: enp3s0 - name: patch-ex-to-phy type: ovs-interface state: up patch: peer: patch-phy-to-ex - name: patch-phy-to-ex type: ovs-interface state: up patch: peer: patch-ex-to-phy - name: enp1s0 type: ethernet state: up ipv4: dhcp: true enabled: true ipv6: enabled: false - name: enp2s0 type: ethernet state: up mtu: 1500 ipv4: enabled: false ipv6: enabled: false - name: enp3s0 type: ethernet state: up mtu: 1500 ipv4: enabled: false ipv6: enabled: false # ...- 1
- 在绑定端口上手动设置
br-exMTU。
使用
base64命令对 NMState 配置文件的接口内容进行编码:$ base64 -w0 <nmstate_configuration>.yml1 - 1
- 其中
-w0选项可防止在 base64 编码操作中换行。
为
master角色和worker角色创建MachineConfig清单文件。确保将之前命令中的 base64 编码的字符串嵌入到每个MachineConfig清单文件中。以下示例清单文件为集群中存在的所有节点配置master角色。您还可以为特定于节点的master和worker角色创建清单文件。apiVersion: machineconfiguration.openshift.io/v1 kind: MachineConfig metadata: labels: machineconfiguration.openshift.io/role: master name: 10-br-ex-master1 spec: config: ignition: version: 3.2.0 storage: files: - contents: source: data:text/plain;charset=utf-8;base64,<base64_encoded_nmstate_configuration>2 mode: 0644 overwrite: true path: /etc/nmstate/openshift/cluster.yml3 将每个
MachineConfig清单文件保存到 ./<installation_directory>/manifests目录,其中 <installation_directory> 是安装程序在其中创建文件的目录。Machine Config Operator (MCO)从每个清单文件中获取内容,并在滚动更新期间持续将内容应用到所有所选节点。