Kubernetes: Ingress
Source material:
- https://www.youtube.com/watch?v=7k4BW6IBRF0
- https://kubernetes.io/docs/concepts/services-networking/ingress/
There are three basic components of an Ingress setup:
- Ingress Service (usually type LoadBalancer)
- Ingress Controller (a Deployment)
- Ingress Rules (configuration on how to route traffic)
We can think of these components as if the Ingress setup was for an office building. An HTTP request is like someone approaching the building, wanting to enter a specific room in the office.
Service
The Ingress service is the main entrance of the office building. This is where all requests start their journey by entering the building through the load balancer.
An Ingress Controller, which runs as a Deployment of Pods, is exposed to the internet by it's own Service of type LoadBalancer
.
Controller
The Ingress controller is the smart receptionist at the desk. It is aware of when a person (HTTP request) has walked through the main entrance. It inspects the HTTP headers and metadata to determine which room it should go to.
Rules
The Ingress rules are the directory of office rooms. The receptionist (Controller) can read these rules and determine the room number (the backend application service) for every path (e.g. foo.com/sales/arizona
-> svc.sales.arizona
Service)
You can configure rules by path (derived from the request URI) or host (derived from the Host header)
Rules are defined in the Ingress
resource, which is nothing but a configuration. Here's a minimal example:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
Other stuff:
IngressClass is a resource that enables a cluster (an office building) to use multiple different Ingress controllers for various use cases.
There are a variety of different Ingress Controllers: NGINX, Traefik, AWS, Google Cloud, etc.
You may deploy any number of ingress controllers using ingress class within a cluster.
Each Ingress Controller has it's own load balancer (service)!