Sub topic 15
Ingress: HTTP routing into the cluster
This chapter assumes you know Pods, Deployments and Services, and that you can apply YAML with kubectl. It builds on the web Service from earlier chapters.
Why Ingress exists
A LoadBalancer Service gives one external load balancer per Service. With ten web apps, that means ten cloud load balancers, each with its own cost and IP address. It also works only at the TCP level, so it cannot route by hostname or URL path.
An Ingress is an API object that holds HTTP and HTTPS routing rules. It lets one entry point send example.com/ to one Service and example.com/api to another.
Ingress needs a controller
An Ingress object is only a set of rules. Nothing acts on it until an Ingress controller is running in the cluster. The controller watches Ingress objects and configures a real proxy, such as NGINX, to follow them. Kubernetes does not ship with a controller.
Each controller registers an IngressClass. An Ingress selects its controller with ingressClassName.
The controller itself is usually exposed through a single LoadBalancer or NodePort Service. That is the one external entry point for all your HTTP traffic.
A basic Ingress
This Ingress sends requests for example.com to the web Service on port 80.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
spec:
ingressClassName: nginx
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80The key fields are:
ingressClassNamepicks the controller. If it names a class with no installed controller, nothing happens.hostmatches the HTTP Host header. If you omit it, the rule matches all hosts.pathandpathTypedecide URL matching.backend.servicenames a Service in the same namespace as the Ingress, plus its port.
Path types
| pathType | Behavior |
|---|---|
| Exact | Matches only the exact path. `/foo` does not match `/foo/`. |
| Prefix | Matches by path elements. `/foo` matches `/foo` and `/foo/bar`, but not `/foobar`. |
| ImplementationSpecific | Matching is left to the controller. |
Checking the result
Run kubectl get ingress web and look at the ADDRESS column. It stays empty until the controller reports an address. Then kubectl describe ingress web shows the rules and whether the backend Service has endpoints.
You can test before DNS exists by sending the Host header yourself: curl -H "Host: example.com" http://<ADDRESS>/.
Common errors
- No controller installed, or a wrong
ingressClassName. The Ingress is accepted but ignored. - The backend Service name or port is wrong. The controller usually returns 503 or 404.
- The Service has no ready endpoints because the readiness probe fails. Check the EndpointSlices.
- The Service is in another namespace. An Ingress can only reference Services in its own namespace.
Exercise
You apply an Ingress and kubectl get ingress shows an empty ADDRESS column after several minutes. The web Service has ready endpoints. What do you check first?
Show answer
Check that an Ingress controller is installed and that its IngressClass matches the Ingress's ingressClassName. Without a matching controller, no component reads the rules or assigns an address.