metalLB
https://metallb.universe.tf/
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml
Create a custom manifest with the IP pool
#Filename metalLB-IPAddressPool.yaml
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: ip-pool
namespace: metallb-system
spec:
addresses:
- 192.168.1.170-192.168.1.179
Apply manifest to cluster
kubectl apply -f metalLB-IPAdressPool.yaml
Testing the MetalLB loadbalancer
kubectl create deployment nginx1 --image=nginx
kubectl expose deployment/nginx1 --type="LoadBalancer" --port 80
Check the nginx service to see what IP was assigned
kubectl get service
Should output something like:
kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 38m
nginx1 LoadBalancer 10.233.36.193 192.168.1.170 80:30490/TCP 40s
IP assigned to that service is 192.168.1.170 and port 80 is exposed externally for that IP. Test with browser with http://192.168.1.170/
Manually assign a static IP
The following manifest is will create a deployment and use a static IP
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
labels:
app: nginx
name: nginx
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
---
apiVersion: v1
kind: Service
metadata:
annotations:
metallb.universe.tf/loadBalancerIPs: 192.168.1.170
labels:
app: nginx
name: nginx
namespace: default
spec:
ports:
- nodePort: 32551
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
sessionAffinity: None
type: LoadBalancer