Setting up Ingress controller NGINX (as a router) along with HAproxy for Microservice deployed inside Kubernetes cluster (Bare-metal servers)
The NGINX Ingress Controller is an Ingress Controller implementation for NGINX and NGINX Plus that can load balance Websocket, gRPC, TCP and UDP applications. It supports standard Ingress features such as content-based routing and TLS/SSL termination. Several NGINX and NGINX Plus features are available as extensions to Ingress resources through Annotations and the ConfigMap resource.
The NGINX Ingress Controller supports the VirtualServer and VirtualServerRoute resources as alternatives to Ingress, enabling traffic splitting and advanced content-based routing. It also supports TCP, UDP and TLS Passthrough load balancing using TransportServer resources.
General Design (big picture) :
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 :
Note: All manifests needed for below steps is present at my github
The Steps :
1) Install NGINX Ingress Controller from 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) :
2) On the nodes, where the PODs 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
3) 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
4) 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
5) Deploy the Services :
kubectl apply -f IngressService.yaml
kubectl apply -f IngressService1.yaml
6) Deploy the Ingress resource :
kubectl apply -f Ingress.yaml
Note: you can also Secure NGINX-ingress via this [Securing NGINX-ingress]
7) HAProxy config as a Load Balancer (On 192.168.56.118) :
sudo nano /etc/haproxy/haproxy.cfg
8) DNS Record (On DNS Server) :
The final results are 🍹 :