One hostname, several Services: the shop's pages from market-web, its API from market-api. The Ingress decides by path.
Prefix and Exact
rules:
- host: market.example
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: market-web
port:
number: 80
- path: /monsters
pathType: Prefix
backend:
service:
name: market-api
port:
number: 8080
- path: /healthz
pathType: Exact
backend:
service:
name: market-api
port:
number: 8080| pathType | /monsters matches | does not match |
|---|---|---|
Prefix | /monsters, /monsters/, /monsters/42 | /monstersx |
Exact | /monsters | /monsters/, /monsters/42 |
Prefix matching is by path segment, so /api never matches /apis. ImplementationSpecific leaves it to the controller; Traefik treats it as a prefix.
The longest match wins
/monsters/42 matches both / and /monsters. The controller picks the most specific rule, the longest path, and Exact beats Prefix at equal length. Order in the file does not matter.
The path is forwarded as is
The backend receives /monsters/42, not /42. Ingress does not strip prefixes by default; the app has to serve under the path it is published on, or the Ingress needs a controller-specific rewrite annotation. Routing /api to a Service that only knows /healthz gives a 404 from the app, not from the controller, which is a different thing to debug.
A default backend
spec:
defaultBackend:
service:
name: market-web
port:
number: 80Requests that match no rule go here instead of the controller's 404 page not found.
Reading it
Rules:
Host Path Backends
---- ---- --------
market.example / market-web:80 (10.42.0.12:80,10.42.0.13:80)
/monsters market-api:8080 (10.42.0.14:8080)
/healthz market-api:8080 (10.42.0.14:8080)