Menu Close
22.4.5. 使用 MetalLB 配置服务
您可以将负载平衡服务配置为使用地址池中的外部 IP 地址。
先决条件
-
安装 OpenShift CLI(
oc
)。 - 安装 MetalLB Operator 并启动 MetalLB。
- 至少配置一个地址池。
- 配置网络,将流量从客户端路由到集群的主机网络。
流程
创建一个
<service_name>.yaml
文件。在文件中,确保将spec.type
字段设置为LoadBalancer
。有关如何请求 MetalLB 分配给服务的外部 IP 地址的信息,请参考示例。
创建服务:
$ oc apply -f <service_name>.yaml
输出示例
service/<service_name> created
验证
描述该服务:
$ oc describe service <service_name>
输出示例
Name: <service_name> Namespace: default Labels: <none> Annotations: metallb.universe.tf/address-pool: doc-example 1 Selector: app=service_name Type: LoadBalancer 2 IP Family Policy: SingleStack IP Families: IPv4 IP: 10.105.237.254 IPs: 10.105.237.254 LoadBalancer Ingress: 192.168.100.5 3 Port: <unset> 80/TCP TargetPort: 8080/TCP NodePort: <unset> 30550/TCP Endpoints: 10.244.0.50:8080 Session Affinity: None External Traffic Policy: Cluster Events: 4 Type Reason Age From Message ---- ------ ---- ---- ------- Normal nodeAssigned 32m (x2 over 32m) metallb-speaker announcing from node "<node_name>"