Install Load Balancer
Install bare-metal Load Balancer service
Add Helm Chart repository:
helm repo add metallb https://metallb.github.io/metallb
helm repo update
Install metallb
as a Load Balancer service:
helm install --create-namespace --namespace metallb metallb metallb/metallb
Configure Load Balancer iptool:
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default
namespace: metallb
spec:
addresses:
- 10.10.10.240-10.10.10.245
autoAssign: true
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: default
namespace: metallb
spec:
ipAddressPools:
- default
Apply the Load Balancer configuration:
kubectl apply -f metallb-iptool.yaml
Verify metallb
deployment installation:
kubectl get -n metallb pods
kubectl logs -n metallb metallb-controller-<Tab>
helm list -n metallb
Intergrate metallb with NGINX Ingress Controller
To complete this task, you need to first install the NGINX Ingress Controller from the previous chapter!
Tell NGINX Ingress Controller to stop using host network:
helm upgrade -n ingress-nginx ingress-nginx ingress-nginx/ingress-nginx --set controller.hostNetwork=false
Check NGINX Ingress Controller:
helm list -n ingress-nginx
Check the External IP of the NGINX Ingress Controller:
kubectl get svc -n ingress-nginx
Deploy test web application
Create a new namespace for the web application:
kubectl create namespace front-web
Create a new application in a specific namespace:
kubectl create deployment -n front-web web-app --image=nginx:1.23 --replicas=3
See created Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web-app
name: web-app
namespace: front-web
spec:
replicas: 3
selector:
matchLabels:
app: web-app
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web-app
spec:
containers:
- image: nginx:1.23
name: nginx
resources: {}
status: {}
Check deployment status:
kubectl get deploy,rs,pods -o wide -n front-web
Expose fronted application with service in mode LoadBalancer
:
kubectl expose deployment -n front-web web-app --port=80 --type=LoadBalancer
See created Service
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: web-app
name: web-app
namespace: front-web
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: web-app
type: LoadBalancer
status:
loadBalancer: {}
Check Service status:
kubectl get svc -n front-web web-app
Output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web-app LoadBalancer 10.106.220.243 10.10.10.241 80:32586/TCP 7s
Try to connect from remote host:
curl http://10.10.10.241
Delete LoadBalancer service:
kubectl delete service -n front-web web-app
Expose once again web-app
with ClusterIP
:
kubectl expose deployment -n front-web web-app --type=ClusterIP --port=80
See created Service
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: web-app
name: web-app
namespace: front-web
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: web-app
type: ClusterIP
status:
loadBalancer: {}
Check service object:
kubectl get svc -n front-web
Configure Ingress for web-app
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: frontend-ingress
namespace: front-web
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
ingressClassName: "nginx"
rules:
- host: front-web.info
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-app
port:
number: 80
Apply Ingress configuration:
kubectl apply -f front-web.yaml
:Check EXTERNAL-IP
for NGINX Ingress Controller:
kubectl get svc -n ingress-nginx ingress-nginx-controller
Output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.109.139.127 10.10.10.240 80:31801/TCP,443:31942/TCP 3h16m
Check connection to web-app
:
curl -D- http://10.10.10.240 -H 'Host: front-web.info'
Clean up:
kubectl delete namespace front-web