---
title: "Gearing up NGINX Kubernetes Ingress Controller"
description: "Learn how to manage multiple incoming services within a Kubernetes cluster with a Kubernetes ingress controller!"
canonical: "https://adamtheautomator.com/kubernetes-ingress/"
---

# Gearing up NGINX Kubernetes Ingress Controller

> Learn how to manage multiple incoming services within a Kubernetes cluster with a Kubernetes ingress controller!

Source: https://adamtheautomator.com/kubernetes-ingress/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Gearing up NGINX Kubernetes Ingress Controller](https://adamtheautomator.com/wp-content/uploads/2021/11/How-to-Setup-an-NGINX-Kubernetes-Ingress-Controller.jpg)

# Gearing up NGINX Kubernetes Ingress Controller

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)2 November 20216 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Kubernetes](/tag/kubernetes/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [What is Kubernetes Ingress Controller?](#what-is-kubernetes-ingress-controller)
*   [Installing NGINX Ingress Controller using Helm](#installing-nginx-ingress-controller-using-helm)
*   [Deploying an NGINX Application and Service](#deploying-an-nginx-application-and-service)
*   [Creating the Ingress resource to expose the NGINX service](#creating-the-ingress-resource-to-expose-the-nginx-service)
*   [Conclusion](#conclusion)

If you need to manage multiple incoming services within the [Kubernetes](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/) cluster from outside the cluster, then configuring an [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) with an [ingress controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/) is the best solution.

Ingress controllers implement networking rules such as incoming TCP connections and routing. One of the most used ingress controllers is NGINX, a powerful web service that acts as an interface between a cluster and the outside work.

In this tutorial, you will learn how to set up an NGINX Kubernetes Ingress Controller step by step. Still interested?

Let’s begin!

## Prerequisites

This post will be a step-by-step tutorial. To follow along, be sure you have:

*   Ubuntu 14.04.4 LTS or greater machine with Docker installed. This tutorial uses [Ubuntu 18.04.5 LTS](https://releases.ubuntu.com/18.04/) with Docker v19.03.8.
*   [kubectl command-line interface](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands)
*   A Kubernetes cluster

Related:[How to Install Kubernetes on an Ubuntu machine](https://adamtheautomator.com/install-kubernetes-ubuntu/)

## What is Kubernetes Ingress Controller?

If you need to expose your application from outside the Kubernetes cluster, you have multiple options like [NodePort](https://kubernetes.io/docs/concepts/services-networking/ingress/), [Load balancer](https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer), and Ingress.

*   Using a Kubernetes service of type [`NodePort`](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport) exposes the application on a port across each of your nodes.
*   Use a Kubernetes service of type [`LoadBalancer`](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer), which creates an external load balancer associated with a specific IP address that points to a Kubernetes service in your cluster.
*   Use a Kubernetes service type `Ingress` when you need to interact and route traffic to multiple Kubernetes services from outside the Kubernetes cluster.

Ingress contains majorly two components: Ingress controller and ingress resources.

*   Ingress resources define all the rules and HTTP/HTTPS routing connectivity from outside the cluster to the Kubernetes services.
*   The ingress controller accepts traffic via an ingress-managed load balancer and then routes traffic to the defined Kubernetes services based on the rules defined in the ingress resources.

As you can see in the below image, the client connects to Kubernetes services in the Kubernetes cluster via ingress managed load balancer and a Ingress controller using Ingress resources that include a set of rules.

![Client request reaching from outside the cluster using Ingress Service and Ingress controller](https://adamtheautomator.com/wp-content/uploads/2021/11/image-7.png)

Client request reaching from outside the cluster using Ingress Service and Ingress controller

## Installing NGINX Ingress Controller using Helm

Let’s now dive into some hands-on tutorials. To get your hands dirty, let’s first set up an ingress controller that defines rules for network connectivity from outside the cluster using ingress resources. You’ll install this ingress controller with [Helm](https://helm.sh/), a popular package manager.

1\. Open your favorite SSH client and connect to your Kubernetes cluster.

2\. Create a folder named _~/nginx-ingress-controller,_ then change (`cd`) the working directory to that folder. This folder will contain all of the configuration files you’ll be working with.

```bash
mkdir ~/nginx-ingress-controller
cd ~/nginx-ingress-controller
```

3\. Next, add an official stable helm repository by running the `curl` command. You must perform this step because, by default, the helm repository is not present in the _/etc/apt/sources.list_ file. This step is to ensure [Helm](https://adamtheautomator.com/kubernetes-helm/) can find the ingress controller package when needed.

```bash
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
```

![Adding an official stable helm repository ](https://adamtheautomator.com/wp-content/uploads/2021/11/image-8.png)

Adding an official stable helm repository

Related:[Getting Started With Kubernetes Helm](https://adamtheautomator.com/kubernetes-helm/)

4\. Now that you have Helm installed on your machine, add the NGINX ingress controller repository using the `helm repo add` command. The NGINX ingress controller repository will contain the charts related to ingress-nginx that will be used for the installation of the ingress controller.

```bash
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
```

If you see below, **ingress-nginx has been added to your repository,** that confirms the successful addition of the ingress-nginx repository in the helm.

5\. Next, update Helm by running the [helm repo update](https://helm.sh/docs/helm/helm_repo_update/#helm-repo-update) command. Helm repo update command updates the information of available charts locally from chart repositories.

6\. Finally, install the NGINX ingress controller by running the `helm install` command. [Helm install command](https://helm.sh/docs/helm/helm_install/) installs an ingress controller using the chart (`ingress-nginx)`. `--set` sets the value of the `controller.publishService.enabled` as true on the command line.

```bash
helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.publishService.enabled=true
```

![Installing the NGINX ingress controller](https://adamtheautomator.com/wp-content/uploads/2021/11/image-9.png)

Installing the NGINX ingress controller

7\. Verify the NGINX ingress controller installed by executing the kubectl get all command. Kubectl command will give you all the details of the cluster.

After successfully executing the command, notice that the ingress controller has two Kubernetes objects; a pod and a service.

*   The pod runs the controller to retrieve the updates from the Ingress Resources by polling the /ingress endpoint.
*   The Service of type LoadBalancer through which the external traffic will flow to the controller, and further, the controller routes the traffic to Kubernetes services, as defined in Ingress Resources.

![ingress controller has two Kubernetes objects](https://adamtheautomator.com/wp-content/uploads/2021/11/image-10.png)

ingress controller has two Kubernetes objects

8\. (Optional) Although you can copy down the details of the load balancer that was created as a service in the previous step or find the details of the load balancer by running the kubectl `get services` command.

`-o wide` provides you detailed information of the Kubernetes object(service)

`EXTERNAL-IP` of the load balancer (**afaf46………..us-east-1.elb.amazonaws.com)** that you will need to configure in the ingress resource file.

```bash
kubectl --namespace default get services -o wide -w nginx-ingress-ingress-nginx-controller
```

![Details of the load balancer](https://adamtheautomator.com/wp-content/uploads/2021/11/image-11.png)

Details of the load balancer

## Deploying an NGINX Application and Service

Previously you installed an ingress controller using the Helm package manager. But before using the ingress controller and ingress, you need a Kubernetes service running in the Kubernetes cluster. Let’s first create a Kubernetes service by following the below steps.

Assuming you’re still connected to your Kubernetes cluster via SSH:

1\. Create a file named NGINX.yaml configuration file in the _~/nginx-ingress-controller_ directory.

The below _nginx.yaml_ file will create the deployment `nginx-deployment` and Kubernetes service named `nginx-service`. This configuration will create a Kubernetes service which will be accessed externally via external ingress load-balanced service.

This deployment will have two replica pods and that the service will host on top of.

```bash
---
# Defining the Kubernetes API version
apiVersion: apps/v1
# Defining the type of the object to create kind: Deployment
# Metadata helps uniquely identify the object, including a name string, UID, and optional namespace.
metadata:
# nginx-deployment as the name of the deployment.
  name: nginx-deployment
# Labels are key/value pairs attached to objects, such as pods. 
# Labels are used to specify identifying attributes of objects that are relevant to users.
  labels:
    app: nginx-first-app
spec:
# replicas: 2 replicas allow you to define the number of pods you need for deployment
  replicas: 2
  selectors:
    matchLabels:
      app: nginx-first-app
  template:
    metadata:
      labels:
        app: nginx-first-app
# spec: Allows you to specify the container details such as the image (nginx) container's name (nginx-pod)
    spec:
      containers:
      - name: nginx-pod
        image: nginx
---
apiVersion: v1
kind: Service
metadata:
# nginx-service as the name of the service.  name: nginx-service
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: nginx-first-app
```

2\. Next, run the [`kubectl apply`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) command to create the deployment and service.

```bash
kubectl apply -f nginx.yaml
```

3\. Finally, verify if the nginx-service is properly configured by running the `kubectl get service` command. This nginx service will be accessed via ingress service of load balancer type.

```bash
kubectl get service nginx-service 
```

![Checking the service that is deployed in the previous section](https://adamtheautomator.com/wp-content/uploads/2021/11/image-12.png)

Checking the service that is deployed in the previous section

## Creating the Ingress resource to expose the NGINX service

Now that you’ve created both the NGINX ingress controller and the Kubernetes services, they aren’t much good unless you create [ingress resource](https://kubernetes.io/docs/concepts/services-networking/ingress/#the-ingress-resource) with the rules to route traffic from ingress controller service (type load balanced) external IP with the kubernetes services.

Lets quickly get into it and create an ingress resource file and apply the configuration.

Assuming you are still on the terminal:

1\. Create a file named _kubernetes-ingress.yaml_ using your favorite editor. The kubernetes-ingress.yaml file contains the rules to route traffic from ingress controller service (type load balanced) external IP with the kubernetes services.

```bash
# Defining the Kubernetes API version
apiVersion:: thetworking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
# External name of the ingress service with an type load balancer
  - host: "afaf46a16b1014f6989bcb22e531f555-149922304.us-east-1.elb.amazonaws.com"
    http:
# Rules 
      paths:
      - pathType: Prefix
        path: "/"
        backend:
# Kubernetes Service that will be redirected from the kubernetes 
          service:
            name: nginx-service
            port:
              number: 80
```

2\. Next, run the `kubectl apply` command to create the ingress resource in the cluster, as shown below. After you will apply the kubernetes-ingress.yaml file in next step it will allow you to access the Kubernetes service from outside the cluster.

```bash
kubectl apply -f Kubernetes-ingress.yaml
```

As you can see below, the kubernetes-ingress resource is created to allow you to access Kubernetes service from outside the cluster from ingress controller service (type load balanced) external IP.

![Creating the Kubernetes ingress](https://adamtheautomator.com/wp-content/uploads/2021/11/image-13.png)

Creating the Kubernetes ingress

3\. Finally, verify if the nginx service is exposed externally by opening your favorite browser and navigate to the load balancers’ external IP address.

As you can see below, the web page displays the Welcome to NGINX page that shows the ingress is set up properly and working fine.

![Verifying the ingress](https://adamtheautomator.com/wp-content/uploads/2021/11/image-14.png)

Verifying the ingress

## Conclusion

In this tutorial, you learned how to install and set up NGINX ingress controller, which can help quickly solve accessing the Kubernetes services on an external URL.

So which all Kubernetes services are you going to access using ingress in the Kubernetes cluster externally?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fkubernetes-ingress%2F&text=Gearing%20up%20NGINX%20Kubernetes%20Ingress%20Controller)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fkubernetes-ingress%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fkubernetes-ingress%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/06/Effortless-Storage-Management-With-Kubernetes-PVC.jpg)

### [Kubernetes PVC for Data Reliability: A Comprehensive Guide](/kubernetes-pvc/)

Tired of Kubernetes storage headaches? Discover how Kubernetes PVC simplifies data persistence and ensures your applications stay up and running.

![](https://adamtheautomator.com/wp-content/uploads/2024/01/kustomize.jpg)

### [A Beginners Guide to Kubernetes Kustomize](/kustomize/)

Dive into Kubernetes Kustomize to master dynamic deployments — A beginner’s guide for personalized configurations and seamless adaptability!

![](https://adamtheautomator.com/wp-content/uploads/2022/06/How-to-Keep-Kubernetes-Secrets-Safe.jpg)

### [Kubernetes Secrets Management: Enhance Safety & Reliability](/kubernetes-secrets/)

Explore expert techniques for securing Kubernetes secrets in production with this guide. Learn to enhance safety and reliability in your Kubernetes deployments.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
