Setting up a Load Balancer¶
A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them.
For some parts of your application (e.g. frontends) you may want to expose a Service onto an external (outside of your cluster) IP address. LoadBalancer service type exposes the service externally using a cloud provider’s load balancer.
Kubernetes does not offer an implementation of network load-balancers (Services of type LoadBalancer) for bare metal clusters. If you’re not running on a supported IaaS platform (GCP, AWS, Azure…), LoadBalancers will remain in the “pending” state indefinitely when created.
Bare metal cluster operators are left with two lesser tools to bring user traffic into their clusters.
MetalLB¶
MetalLB aims to redress this imbalance by offering a Network LB implementation that integrates with standard network equipment, so that external services on bare metal clusters also “just work” as much as possible.
Prerequisite¶
In order for this solution to work you must configure your cluster worker nodes with a public ip.
Installation¶
$ kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.2/manifests/metallb.yaml
Configuration¶
$ kubectl apply -f configuration_file.yaml
where a configuration file example is:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- <IP range start>-<IP range end>
- <CIDR prefix>