Get 'External IP' for pods in Bare Metal /On Prem Kubernetes

1/28/2020

I want to expose pods with external public IPs (not using NodePort option). Please let me know a way to achieve it (in detail) in Bare Metal Kubernetes (without using a cloud provider). I have tried MetalLB, but was unsuccessful as the IP ranges are different from my nodes.

My configuration is as follows

 apiVersion: v1
 kind: ConfigMap
 metadata:
   namespace: metallb-system        
   name: config
 data:
   config: |
     address-pools:
     - name: default
       protocol: layer2
       addresses:
       - 192.249.6.75-192.249.6.79


kubectl get pods -o wide --all-namespaces

<output omitted>
metallb-system         controller-65895b47d4-cbnpd                                  1/1     Running            1          26d   192.168.182.12    worker3   <none>           <none>
metallb-system         speaker-6zfw8                                                1/1     Running            1          26d   192.168.56.102    worker1   <none>           <none>
metallb-system         speaker-76hvg                                                1/1     Running            1          26d   192.168.56.103    worker2   <none>           <none>
metallb-system         speaker-qkpwb                                                1/1     Running            2          26d   192.168.56.101    master    <none>           <none>
metallb-system         speaker-qqhng                                                1/1     Running            1          26d   192.168.56.104    worker3   <none>           <none>

Node subnet CIDR is 192.168.0.0/16.

Thanks.

-- dsw
kubernetes
metallb

1 Answer

2/6/2020

you can configure IP ranges for metalLB in it's config: see configuration section

note however that LoadBalancer type services always have to have IPs different than the nodes, regardless what implementation of the external LB you are using. otherwise locally open ports on nodes would be clashing with services port.

update

when using metalLB in L2 mode the address pool must be within the CIDR of the (V)LAN where the nodes are located, otherwise the ARP will not work. change your metalLB config for example to 192.168.100.10-192.168.100.20 (make sure that it does not clash with any existing machines on your network and ideally reconfigure dhcp so that its pool for new machines doesn't clash metalLB's one)

-- morgwai
Source: StackOverflow