NGINX: Introduction to The Most Popular Ingress Controller in Kubernetes World

8grams
3 min readMay 5, 2023
Nginx

Introduction

Hey there, fellow tech enthusiasts! Today, we're going to have a laid-back discussion about Ingress and Ingress NGINX in the world of Kubernetes. We'll explore what Ingress is, its role in Kubernetes clusters, and why we'd want to use Ingress NGINX. So, sit back, relax, and let's roll in!

What is Ingress?

Source: https://www.nginx.com/

Ingress in Kubernetes

In Kubernetes, Ingress is an essential component that helps manage external access to the services running within a cluster. Think of it as a gateway or entry point that controls and routes traffic from outside the cluster to the right services inside it. Ingress lets you define rules and policies for routing external traffic, which can be pretty useful for load balancing, SSL termination, and name-based virtual hosting.

The role of Ingress in Kubernetes clusters

A Kubernetes cluster can have multiple services running, and each service might expose an API or serve web content. So, without Ingress, we would need to expose each service with a separate external IP address, which is not ideal.

Ingress simplifies this process by providing a single point of entry for external traffic. It listens for incoming requests on specific ports or domains and routes them to the right services based on the predefined rules. This way, you can expose multiple services using a single external IP address.

For example, let's say you have two services, one for an online store (store.example.com) and another for a blog (blog.example.com). You can create an Ingress resource that routes incoming traffic based on the requested hostnames to the appropriate services.

Why Ingress Nginx?

The need for an Ingress Controller

Ingress resources in Kubernetes don't do the magic all by themselves. They need an Ingress Controller to implement the actual routing rules. An Ingress Controller is a component that watches for Ingress resources and updates the underlying routing infrastructure based on the defined rules.

There are many Ingress Controllers available, such as HAProxy, Traefik, and Istio. However, one of the most popular and widely used controllers is NGINX.

Advantages of Ingress NGINX

Ingress NGINX is a popular choice for several reasons:

  • Performance: NGINX is known for its high performance and ability to handle a massive number of concurrent connections with minimal resource consumption.
  • Flexibility: Ingress NGINX allows you to easily customize and extend its functionality using annotations, ConfigMaps, and custom templates.
  • Community support: As a widely used Ingress Controller, Ingress NGINX has an extensive and active community. This means you can easily find support, solutions, and examples when you need help.
  • Ease of use: Setting up and configuring Ingress NGINX is straightforward, making it an excellent choice for those just getting started with Kubernetes.

Setting up Ingress NGINX in Your Kubernetes Cluster

Deploying Ingress NGINX using Helm

Before proceeding with the installation of NGINX on your Kubernetes cluster, it's important to ensure that Helm is installed and properly configured. Helm is a package manager for Kubernetes, which simplifies the deployment and management of applications on a cluster. In this guide, we will be using the official NGINX Helm chart.

Add Helm Chart

~$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
~$ helm repo update

Create Helm values file

Ingress Nginx Helm Values

Install to cluster

~$ helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --version 4.2.5 --values deployment.yaml --create-namespace

Verifying Ingress Nginx installation

To verify that Ingress Nginx is running, you can check the pods in the ingress-nginx namespace:

~$ kubectl get pods --namespace=ingress-nginx

NAME READY STATUS RESTARTS AGE
ingress-... 1/1 Running 0 16d

Configuring Ingress NGINX

Example of basic Ingress configuration

These examples will show how Ingress NGINX is really easy to customize

  • Defining routing rules
    Create a simple Ingress resource that routes traffic based on the host:
  • Using Load balancing algorithms
    Configure the load balancing algorithm using the nginx.ingress.kubernetes.io/load-balance annotation:
  • Rewrites and redirects
    To rewrite or redirect requests

Create username and password for Basic Auth

~$ htpasswd -c auth myusername
~$ kubectl create secret generic basic-auth-secret --from-file=auth

Implement to Ingress

--

--

8grams

We are a DevOps Consulting Firm with a mission to empower businesses with modern DevOps practices and technologies