Setup MetalLB for Kubernetes
![Setup MetalLB for Kubernetes](/content/images/size/w960/2023/02/cover-1.jpg)
This post is more like a note to myself, but this may help if you are looking at How to Setup MetalLB for Kubernetes.
Introduction
MetalLB hooks into your Kubernetes cluster, and provides a network load-balancer implementation. In short, it allows you to create Kubernetes services of type LoadBalancer
in clusters that don’t run on a cloud provider, and thus cannot simply hook into paid products to provide load balancers.
Why
Kubernetes does not offer an implementation of network load-balancers (Services of type LoadBalancer) for bare metal clusters. The implementations of Network LB that Kubernetes does ship with are all glue code that calls out to various IaaS platforms (GCP, AWS, Azure…). If you’re not running on a supported IaaS platform (GCP, AWS, Azure…), Load Balancers will remain in the “pending” state indefinitely when created.
Kubernetes Env
Server | IP | Role |
---|---|---|
bogor-master | 10.20.12.100 | master |
bogor-worker1 | 10.20.12.101 | worker |
bogor-worker2 | 10.20.12.102 | worker |
Setup MetalLB
Install MetalLB and Spesify Address to use as LoadBalancer
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
cat<<EOF >> configmap.yaml
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: first-pool
namespace: metallb-system
spec:
addresses:
- 10.20.12.155-10.20.12.170
EOF
kubectl apply -f configmap.yaml
Verify Installation
kubectl get all -n metallb-system
Operational Test
kubectl create deployment nginx --image nginx:alpine
kubectl expose deployment nginx --type LoadBalancer --port 80
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 23d
service/nginx LoadBalancer 10.233.59.192 10.20.12.164 80:32061/TCP 3s
![](https://rjhaikal.my.id/content/images/2023/02/1.png)
Reference
![](https://metallb.universe.tf/images/logo/metallb-white.png)
Member discussion