Sub topic 2
Why Ingress exists
This chapter assumes you can run Pods, Deployments, and ClusterIP Services, apply YAML with kubectl, and read basic HTTP (hosts, paths, status codes). It explains the problem Ingress solves. Later chapters cover the manifest details.
Services are the targets
Ingress routes traffic to Services, not directly to Pods. A ClusterIP Service gives a set of Pods one stable virtual IP and DNS name inside the cluster. This one will be the backend in later examples:
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 8080Requests to port 80 of web go to port 8080 on Pods labeled app: web. A ClusterIP is reachable only from inside the cluster, so something else has to carry outside traffic in.
Exposing Services without Ingress
Kubernetes has two built-in ways to expose a Service externally. Both work, and both get awkward as you add Services.
NodePort opens the same port on every node, from 30000 to 32767 by default. Clients must know a node IP and an unusual port. Each Service takes its own port, and nodes can be replaced or change addresses.
LoadBalancer asks the cloud provider for an external load balancer in front of one Service. The address is stable, but you get one load balancer per Service. With 20 Services you pay for and manage 20 load balancers and 20 public IPs. These load balancers usually work at layer 4 (TCP), so they cannot choose a backend by hostname or URL path.
| Approach | Entry points | Routes by host or path | Where TLS lives |
|---|---|---|---|
| NodePort | One port per Service, on every node | No | In each application |
| LoadBalancer | One external load balancer per Service | No (layer 4) | In each application, or per load balancer |
| Ingress | One shared entry point | Yes (layer 7) | Once, at the entry point |
What Ingress adds
Web traffic usually needs rules such as these:
shop.example.com/apigoes to theapiService.shop.example.com/goes to thewebService.blog.example.comgoes to a different Service entirely.- HTTPS is handled once, not separately in every application.
These rules work at layer 7, where the request's host header and path are visible. Ingress is the Kubernetes API for declaring them. You describe the rules in one Ingress resource, and traffic enters through one shared address. You can add a Service by adding a rule instead of provisioning another load balancer.
Two parts: resource and controller
Ingress has two parts, and mixing them up causes many problems.
- The Ingress resource is an API object that holds your routing rules. It is configuration only and does not move any traffic.
- The Ingress controller is a program running in the cluster, usually as Pods. It watches Ingress resources and configures a real proxy or load balancer to match.
The controller itself still needs an external entry point, typically one LoadBalancer or NodePort Service. That is the shared entry point, so you pay for it once instead of once per application.
When Ingress is not the answer
Ingress is designed for HTTP and HTTPS. For raw TCP or UDP services such as a database, a LoadBalancer or NodePort Service is still the usual choice. Ingress also has a small standard feature set, so behavior like rewrites and rate limits depends on the controller. A later chapter covers that portability limit and the Gateway API, which addresses it.
Exercise
Your cluster has 15 web applications that each need public HTTPS access on their own hostname. You have created an Ingress resource for each one, but none of them receive traffic and kubectl get ingress shows no address. What is the most likely cause, and why does Ingress still reduce cost compared to 15 LoadBalancer Services?
Show answer
Most likely no Ingress controller is installed, or none claims these Ingresses. The resources are only rules, and a controller must read them and configure a proxy. Ingress still reduces cost because all 15 hostnames share one controller and one external entry point, so you need one load balancer instead of 15.