Install MetalLB load balancer for Kubernetes
Page content
In this tutorial iwill show you how to install Metal LB load balancer running on Kubernetes (k8s).
Parst of the Openshift series
- Part1: Install K8S with ansible
- Part2: Install K8S with kubeadm
- Part3: Install ingress to K8S
First we need to apply the MetalLB manifest.
kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.1/manifests/metallb.yaml
Create a metallb-configmap.yaml file and modify your IP range accordingly.
cat <EOF>> metallb-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: my-ip-space
protocol: layer2
addresses:
- 192.168.10.240-192.168.10.250
EOF
kubectl apply -f metallb-config.yaml
kubectl get pods -n metallb-system
Exposing a service through the load balancer
cat <EOF>> nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- port: 80
name: http
EOF
kubectl apply -f nginx-deployment.yaml
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx LoadBalancer 10.109.51.83 192.168.10.241 80:30452/TCP 5m