Setting up Ingress controller NGINX (as a router) along with HAproxy for Microservice deployed inside Kubernetes cluster (Bare-metal servers)
General Design (big picture) :
All files needed for deployments are available at Manifests folder.
The control-plane & worker nodes addresses are :
192.168.56.115
192.168.56.116
192.168.56.117
and HAProxy as a Load Balancer :
192.168.56.118
Kubernetes cluster nodes :
The Steps :
- Install NGINX Ingress Controller from :
https://docs.k0sproject.io/main/examples/nginx-ingress
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/baremetal/deploy.yaml
kubectl get all --namespace=ingress-nginx
Ingress-Nginx workloads (ingress port in our case is 30798) :
- On the node, where the POD will be located (node1 and node2 in our case) :
DIRNAME="vol1"
mkdir -p /mnt/disk/$DIRNAME
chcon -Rt svirt_sandbox_file_t /mnt/disk/$DIRNAME
chmod 777 /mnt/disk/$DIRNAME
- Deploy the Storage Class & PV & PVC :
kubectl apply -f storageClass.yaml
kubectl apply -f persistentVolume.yaml
kubectl apply -f persistentVolume1.yaml
kubectl apply -f persistentVolumeClaim.yaml
kubectl apply -f persistentVolumeClaim1.yaml
- Deploy the web apps :
kubectl apply -f http-pod.yaml
kubectl apply -f http-pod1.yaml
Get pod ip & curl the related web app :
POD_IP=$(kubectl get pod www2-c5644ff98-trk4d -o yaml | grep podIP | awk '{print $2}'); echo $POD_IP
curl $POD_IP
- Deploy the Services :
kubectl apply -f IngressService.yaml
kubectl apply -f IngressService1.yaml
- Deploy the Ingress resource :
kubectl apply -f Ingress.yaml
Note: you can also Secure NGINX-ingress via this Securing NGINX-ingress
- HAProxy config as a Load Balancer (On 192.168.56.118) :
sudo nano /etc/haproxy/haproxy.cfg
- DNS Record (On DNS Server) :
The final results are 🍹 :