与其他一些负载均衡器实现一样,MetalLB 接受服务规范中的spec.loadBalancerIP
字段。
如果请求的 IP 地址在任何地址池的范围内,MetalLB 将分配请求的 IP 地址。如果请求的 IP 地址不在任何范围内,MetalLB 将报告警告。
特定 IP 地址的服务 YAML 示例
apiVersion: v1
kind: Service
metadata:
name: <service_name>
annotations:
metallb.universe.tf/address-pool: <address_pool_name>
spec:
selector:
<label_key>: <label_value>
ports:
- port: 8080
targetPort: 8080
protocol: TCP
type: LoadBalancer
loadBalancerIP: <ip_address>
如果 MetalLB 无法分配请求的 IP 地址,则服务的EXTERNAL-IP
将报告<pending>
,并且运行oc describe service <service_name>
将包含以下示例事件。
MetalLB 无法分配请求的 IP 地址时的示例事件
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning AllocationFailed 3m16s metallb-controller Failed to allocate IP for "default/invalid-request": "4.3.2.1" is not allowed in config