How to Expose a Kubernetes MetalLB Load Balancer in a Virtual Network
PreviousCNI Fails on New Node Due to x86-64-v2 CPU IncompatibilityNextVM HA Heartbeat Failures Triggering VM Evacuations
Last updated
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: virtual-net-pool
namespace: metallb-system
spec:
addresses:
- 192.168.1.233-192.168.1.233apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: virtual-net-l2
namespace: metallb-system
spec:
ipAddressPools:
- virtual-net-poolopenstack port create \
--network <VIRTUAL_NETWORK_NAME_OR_UUID> \
--fixed-ip subnet=<VIRTUAL_SUBNET_NAME_OR_UUID>,ip-address=192.168.1.233 \
metallb-vip-port# Allocate a new floating IP if you don't have one
openstack floating ip create <EXTERNAL_NETWORK_NAME>
# Associate it with the MetalLB VIP port
openstack floating ip set \
--port <METALLB_VIP_PORT_UUID> \
--fixed-ip-address 192.168.1.233 \
<FLOATING_IP_ADDRESS>kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx \
--port=80 --target-port=80 \
--type=LoadBalancer \
--name=nginx-lbkubectl get svc nginx-lb
# NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
# nginx-lb LoadBalancer 10.96.130.137 192.168.1.233 80:32456/TCP 1mcurl http://<FLOATING_IP_ADDRESS>:80 -I
# HTTP/1.1 200 OK