NGINX Ingress Controller with HAProxy for k8s cluster

$ kubectl patch svc <application-name> -n <name-of-namespace> -p ‘{“spec”: {“type”: “LoadBalancer”, “externalIPs”:[“<haproxy-ip-address>”]}}’

What is ingress controller ?

Updates to cluster

  • Create VMs
  • Setup SSH connection
  • Use KubeSpray to deploy cluster
  • Create HAProxy and establish SSH connection with all nodes.
  • Enable ingress controller from inventory file inside KubeSpray
$ vim inventory/mycluster/group_vars/k8s-cluster/addons.yml
# Nginx ingress controller deployment
ingress_nginx_enabled: false -> true
$ ansible-playbook -i inventory/mycluster/hosts.yaml — become — become-user=root cluster.yml
  • Include Ingress API object to route traffic from external HAProxy server to internal services
$ vim /etc/haproxy/haproxy.cfgfrontend kubernetes-ingress-http
bind *:80
default_backend kubernetes-worker-nodes-http
backend kubernetes-worker-nodes-http
balance leastconn
option tcp-check
server worker1 10.0.128.81:80 check fall 3 rise 2
server worker2 10.0.128.137:80 check fall 3 rise 2
server worker3 10.0.128.156:80 check fall 3 rise 2
  • Setup NGINX Ingress Controller
NGINX Ingress Controller
Overview of HA Kubernetes Cluster
Overview of HA k8s cluster

Steps to create NGINX Ingress controller

  • Clone Ingress Controller Repo
$ git clone https://github.com/nginxinc/kubernetes-ingress/
$ cd kubernetes-ingress
  • Create a namespace and a service account for the Ingress controller
$ kubectl apply -f common/ns-and-sa.yaml
  • Create a cluster role and cluster role binding for the service account
$ kubectl apply -f rbac/rbac.yaml
  • Create a secret with a TLS certificate and a key for the default server in NGINX
$ kubectl apply -f common/default-server-secret.yaml
$ kubectl apply -f common/nginx-config.yaml
$ kubectl apply -f daemon-set/nginx-ingress.yaml
$ kubectl get allNAME READY STATUS RESTARTS AGE
pod/nginx-ingress-47z8r 1/1 Running 0 24h
pod/nginx-ingress-cmkfq 1/1 Running 0 24h
pod/nginx-ingress-ft5pv 1/1 Running 0 24h
pod/nginx-ingress-q554l 1/1 Running 0 24h
pod/nginx-ingress-ssdrj 1/1 Running 0 24h
pod/nginx-ingress-t9jml 1/1 Running 0 24h
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/nginx-ingress 6 6 6 6 6 <none> 24h

Deploy Example Application

  • Create a sample NGINX Web Server (Using provided example)
Example NGINX Deployment
$ kubectl apply -f https://k8s.io/examples/application/deployment.yaml## or you can do same thing with local file as given below$ kubectl apply -f nginx-deploy-main.yml
$ kubectl expose deploy nginx-deployment --port 80
Ingress Ruleset
Ingress rules for different services
$ kubectl create -f nginx-ingress-resource.yml
Example NGINX Web Server Deployment Result

--

--

--

Software Engineer at Aalborg University, Denmark

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Is There Any Unlimited Text-To-Speech Converter For Free In 2022?

Create and maintain simple web APIs from the command line using AWS Python 3 Lambda functions, AWS…

How to use a Quest 2 for Desktop-Quality Wireless VR

A highly available Tezos baker on Kubernetes

Guide to ExecutionException in Java

8 Things to do after installing Ubuntu 18.04

Microservice Security and CD Pipelines- How Much is Just Enough

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmet Türkmen

Ahmet Türkmen

Software Engineer at Aalborg University, Denmark

More from Medium

Monitoring Camel K applications using Prometheus and Grafana

Monitoring multiple federated instances with Prometheus

Deploy and use ArgoCD with Portainer (Part 1)

OAuth2 Proxy 4— Secure between Router and OAuth2 Proxy