⚖️
Kubernetes

LoadBalancer Service

Expose app with LoadBalancer — cloud LB or MetalLB on bare metal

📋Configuration Files

deployment.yml

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: web
5spec:
6 replicas: 3
7 selector:
8 matchLabels:
9 app: web
10 template:
11 metadata:
12 labels:
13 app: web
14 spec:
15 containers:
16 - name: nginx
17 image: nginx:alpine
18 ports:
19 - containerPort: 80

service-loadbalancer.yml

LoadBalancer assigns external IP (cloud) or MetalLB IP

yaml
1apiVersion: v1
2kind: Service
3metadata:
4 name: web-lb
5spec:
6 type: LoadBalancer
7 selector:
8 app: web
9 ports:
10 - port: 80
11 targetPort: 80
12 protocol: TCP
📄

Step 01

Apply LoadBalancer

(01)Deploy to cluster

Linux
1kubectl apply -f .
2kubectl get all
3kubectl get pods -w

(02)Remove

Linux
1kubectl delete -f .