Kubernetes Ingress: Nginx Ingress Edition

Prerequisites

To follow along with this blog post, you should have:

  • Minikube installed OR have a Kubernetes cluster already running on-prem or in the cloud.

What’s Ingress?

How does an application reach the public internet with, say, a Kubernetes Deployment or a Kubernetes Pod? It does so by utilizing a Kubernetes Service. A Kubernetes Service can attach a load balancer, whether you’re in the cloud or on-prem, to the Kubernetes Service so people (clients, customers, yourself, etc.) can reach the application publically.

ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
  • There is a path key/value mapping that shows what path you’ll be able to reach the application on via the load balancer. It could look something like http://load_balancer_name/testpath
  • There is a service key/value mapping that points to the Kubernetes Service name and the port that the Service is running on. In this case, the name of the service is test

Why Is It Needed?

In the previous section, you learned about what Ingress is. Now let’s talk about why it’s needed.

  • Cloud load balancers are expensive
  • If you use an on-prem solution, chances are you have to set up BGP so you don’t run into ARP requests
  • Who wants to manage multiple cloud load balancers?
  • Who wants to manage BGP?

Getting Started With Nginx Ingress

As with all Kubernetes resources, there’s a Kind/Spec for Nginx Ingress and an API. The API is from the Named API Group.

KIND:     IngressClass                                                               
VERSION: networking.k8s.io/v1

Installing an Ingress Controller

For installing an Ingress Controller, it’s all going to depend on what platform you’re using. The installation methods are all sort of the same, as in using a Helm chart to install Nginx Ingress, but some options and flags may vary based on what Kubernetes cloud or on-prem service you’re using.

Running an Ingress Controller

Now that Nginx Ingress is installed, let’s look at how to get an application up and running to use Nginx Ingress.

  • An Nginx Deployment spec
  • A Service Deployment spec
apiVersion: apps/v
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginxdeployment
replicas: 2
template:
metadata:
labels:
app: nginxdeployment
spec:
containers:
- name: nginxdeployment
image: nginx:latest
imagePullPolicy: Never
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginxservice
spec:
selector:
app: nginxdeployment
ports:
- protocol: TCP
port: 80
kubectl create -f deployment.yaml
  • The Kubernetes Service name is the same name as the Service you created in the previous Kubernetes Manifest. That’s because the Ingress Controller has to point to the Kubernetes Service
  • The host is pointing to localhost with the assumption that you’re using Minikube.
  • The port is 8080
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginxservice-a
spec:
ingressClassName: nginx-servicea
rules:
- host: localhost
http:
paths:
- path: /nginxappa
pathType: Prefix
backend:
service:
name: nginxservice
port:
number: 8080
kubectl create -f ingress.yaml

Other Ingress Controllers

Although Nginx Ingress is one of the most popular ingress controllers, there are several others ranging from open-source projects to large organizations creating it’s own implementation of ingress controllers. Below is a list of ingress controllers and this comes directly from the Kubernetes website: https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/

--

--

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
Michael Levan

Michael Levan

234 Followers

Leader in Kubernetes consulting, research, and content creation ┇AWS Community Builder (Dev Tools Category)┇ HashiCorp Ambassador