Platform9 Blog

How To Set Up NGINX Ingress Controller On Kubernetes Using Platform9

In this article, you will learn how to set up NGINX Ingress Controller on Kubernetes using a free Platform9 Kubernetes account.

The Need For Ingress Controllers With Kubernetes

The vast majority of Kubernetes clusters are used to host containers that process incoming requests from micro-services to full web applications. Having these incoming requests come into a central location, then get handed out via services in Kubernetes, is the most secure way to configure a cluster.

Ingress is used as an entry point for clients to publicly access the services on a Kubernetes cluster. In the absence of an ingress, the services are typically exposed to the outside via a Kubernetes resource of the type LoadBalancer. Load balancers are expensive resources in the cloud and using them for every service is just not practical even in your on-premises private cloud. Ingress controllers not only solve this problem but also provide additional features like SSL termination and host-based or path-based routing.

Ingress overcomes restrictions with using Kubernetes services like nodePort where one is restricted to use port 30000 and above. Cloud load balancers also overcome this restriction but at a higher cost as the services that are exposed grow the number of load balancers that required also keep growing. Cloud load balancers are expensive. This is where an ingress controller has an advantage as it can expose multiple services using a single cloud load balancer.

The cloud load balancer talks with ingress which in turn routes the traffic to an underlying service on Kubernetes. In Kubernetes both LoadBalancer and ingress have service endpoints connected with each other. On public clouds ingress controllers can provision cloud load balancers for themselves, whereas private cloud clusters use MetalLB as load balancer.

Read on to learn how to deploy the NGINX Ingress Controller on Kubernetes using a free Platform9 Managed Kubernetes cluster.

Getting Started

To get started, create your free Platform9 Kubernetes account by entering your email below, then select the ‘Deploy Now’ option. Once you have created and verified your account, follow the steps outlined below. 

Step 1: Create your free account

Step 1: Create your free account

In addition to the Platform9 Managed Kubernetes account, you will use a MetalLB load balancer on baremetal servers/VMs running Ubuntu 18.04 or CentOS 7.6.

Deployment of NGINX Ingress Controller on Kubernetes

To deploy the NGINX Ingress Controller on Kubernetes, clone the ingress repository in KoolKubernetes organization and apply it on your cluster.

$ git clone https://github.com/KoolKubernetes/ingress.git

$ kubectl apply -f ingress/nginx/nginx-v0.33.0.yaml
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
configmap/ingress-nginx-controller created
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created
role.rbac.authorization.k8s.io/ingress-nginx created
rolebinding.rbac.authorization.k8s.io/ingress-nginx created
service/ingress-nginx-controller-admission created
service/ingress-nginx-controller created
deployment.apps/ingress-nginx-controller created
validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created
clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
job.batch/ingress-nginx-admission-create created
job.batch/ingress-nginx-admission-patch created
role.rbac.authorization.k8s.io/ingress-nginx-admission created
rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
serviceaccount/ingress-nginx-admission created

Validate the ingress controller pods are running. Notice that NGINX ingress has got the load balancer IP from MetalLB.

$ kubectl get ns ingress-nginx
NAME            STATUS   AGE
ingress-nginx   Active   80s

$ kubectl get all -n ingress-nginx
NAME                                            READY   STATUS      RESTARTS   AGE
pod/ingress-nginx-admission-create-9dt62        0/1     Completed   0          82s
pod/ingress-nginx-admission-patch-fzlvg         0/1     Completed   0          82s
pod/ingress-nginx-controller-58f68f5ccc-c9gmt   1/1     Running     0          93s


NAME                                         TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                      AGE
service/ingress-nginx-controller             LoadBalancer   10.21.21.80    10.128.231.209   80:32755/TCP,443:32569/TCP   93s
service/ingress-nginx-controller-admission   ClusterIP      10.21.109.77   <none>           443/TCP                      93s


NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           93s

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-58f68f5ccc   1         1         1       93s


NAME                                       COMPLETIONS   DURATION   AGE
job.batch/ingress-nginx-admission-create   1/1           6s         92s
job.batch/ingress-nginx-admission-patch    1/1           8s         92s

Clone the cicd repo to test the ingress controller with the pf9-react-app.

$ git clone https://github.com/KoolKubernetes/cicd.git

Deploy the app with ingress resource to leverage NGINX ingress controller.

$ kubectl apply -f cicd/jenkins/webapp01/k8s/ingress-nginx-app.yaml
namespace/p9-react-app created
deployment.apps/p9-react-app created
service/p9-react-app created
ingress.networking.k8s.io/pf9app-routing created

Validate the app is running in p9-react-app namespace with an ingress resource.

$ kubectl get all -n p9-react-app
NAME                                READY   STATUS    RESTARTS   AGE
pod/p9-react-app-67d4df6bb6-5f944   1/1     Running   0          17s
pod/p9-react-app-67d4df6bb6-t8p45   1/1     Running   0          17s


NAME                   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
service/p9-react-app   ClusterIP   10.21.39.141   <none>        80/TCP    18s


NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/p9-react-app   2/2     2            2           18s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/p9-react-app-67d4df6bb6   2         2         2       18s

$ kubectl get ingress -n p9-react-app
NAME             HOSTS                    ADDRESS         PORTS   AGE
pf9app-routing   pf9app.platform9.horse   10.128.229.21   80      40m

The ingress resource gets created as shown below.

$ kubectl describe ingress -n p9-react-app
Name:             pf9app-routing
Namespace:        p9-react-app
Address:          10.128.229.21
Default backend:  default-http-backend:80 (<none>)
Rules:
  Host                    Path  Backends
  ----                    ----  --------
  pf9app.platform9.horse
                          /   p9-react-app:80 (10.20.20.22:80,10.20.96.22:80)
Annotations:
  kubectl.kubernetes.io/last-applied-configuration:  {"apiVersion":"networking.k8s.io/v1beta1","kind":"Ingress","metadata":{"annotations":{},"name":"pf9app-routing","namespace":"p9-react-app"},"spec":{"rules":[{"host":"pf9app.platform9.horse","http":{"paths":[{"backend":{"serviceName":"p9-react-app","servicePort":80},"path":"/"}]}}]}}

Events:
  Type    Reason  Age                  From                      Message
  ----    ------  ----                 ----                      -------
  Normal  CREATE  45m                  nginx-ingress-controller  Ingress p9-react-app/pf9app-routing

The Service p9-react-app within Kubernetes namespace p9-react-app is now exposed outside via hostname pf9app.platform9.horse. One should make a local hosts file entry to visit this URL from the LAN. Modify the Manifest to set the hostname of your choice before deploying the app manifest on the cluster.

Ingress controller should be running on a node which has enough resources. It can be further configured to add authentication, TLS termination, etc.

References

https://kubernetes.github.io/ingress-nginx/examples/

https://kubernetes.github.io/ingress-nginx/

Next Steps

In this blog, we walked through a tutorial on how to set up NGINX Ingress Controller on Kubernetes. We hope you found this blog informative and engaging. For more reads like this one, visit our blog page or subscribe for up-to-date news, projects, and related content in real-time.   

Check out our additional complete stack projects in our Github repos

You may also enjoy

Announcing the Industry’s Only SaaS Managed Bare Metal Orchestration Platform

By Rohan Shah

How To Set Up Kubevirt For Kubernetes Based VM Management

By Peter Fray

The browser you are using is outdated. For the best experience please download or update your browser to one of the following: