我正在尝试创建具有相同IP地址的负载均衡器:192.168.1.10 这就是我到目前为止所做的 但是,我收到如下错误消息:
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning AllocationFailed 39m metallb-controller Failed to allocate IP for "vpn/service2-loadbalancer": can't change sharing key for "vpn/service2-loadbalancer", address also in use by vpn/service1-loadbalancer
apiVersion: v1
kind: Service
metadata:
name: service1-loadbalancer
namespace: vpn
annotations:
metallb.universe.tf/allow-shared-ip: 192.168.1.10
labels:
app: service1
spec:
type: LoadBalancer
externalTrafficPolicy: Local
ports:
- name: udp-port-1
port: 51820
protocol: UDP
targetPort: 51820
- name: tcp-port-1
port: 3000
protocol: TCP
targetPort: 3000
selector:
app: service1
# creates TCP 192.168.1.10:3000, UDP 192.168.1.10:51820
apiVersion: v1
kind: Service
metadata:
name: service2-loadbalancer
namespace: vpn
annotations:
metallb.universe.tf/allow-shared-ip: 192.168.1.10
labels:
app: service2
spec:
type: LoadBalancer
externalTrafficPolicy: Local
ports:
- name: udp-port-2
port: 51821
protocol: UDP
targetPort: 51821
- name: tcp-port-2
port: 3001
protocol: TCP
targetPort: 3001
selector:
app: service2
# expects TCP 192.168.1.10:3001, UDP 192.168.1.10:51821
初始创建MetalLB地址池,示例如下:
apiVersion: metallb.io/v1alpha1
kind: AddressPool
metadata:
namespace: metallb-system
name: <address_pool_name>
spec:
protocol: layer2
addresses:
- 1.2.3.4-1.2.3.4
然后使用 metalLB 注释创建您的服务
apiVersion: v1
kind: Service
metadata:
name: svc1
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: 1.2.3.4
---
apiVersion: v1
kind: Service
metadata:
name: svc2
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: 1.2.3.4
您也可以参考以下文档: