Ingress Rules: Path-Based & Host-Based Routing
Route external HTTP traffic by host and path to backend Services.
In plain words
Ingress rules are the mail-room sorter: the envelope's Host selects a department and its path selects the internal tray. The simple Kubernetes rule is: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
Think of it like…
Ingress rules are the mail-room sorter: the envelope's Host selects a department and its path selects the internal tray.
Where you’ve seen it
During a connectivity incident, the network owner runs kubectl get ingress shop -o yaml; kubectl describe ingress shop. Expected evidence: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation. If the run instead shows this symptom, stop and restore the last known state: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge.
Words you’ll hear
- Host Rules
- For this lesson, Host Rules is the controlling idea: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
- Path Rules
- Path Rules is the checkpoint; run
kubectl get ingress shop -o yaml; kubectl describe ingress shopand inspect the owner chain. Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge. - Backends
- Backends is the outcome to preserve; the cost is explicit: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.
- Verification evidence
- The evidence command is
kubectl get ingress shop -o yaml; kubectl describe ingress shop. It connects the declaration to this behavior: Route external HTTP traffic by host and path to backend Services.
Visual diagram
Theory & deep dive
How Host Rules reaches the intended state
Route external HTTP traffic by host and path to backend Services. Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
The concrete checkpoint is kubectl get ingress shop -o yaml; kubectl describe ingress shop; compare the Host Rules owner, Path Rules state, and Backends outcome instead of treating YAML acceptance as proof.
Run kubectl get ingress shop -o yaml; kubectl describe ingress shop after the change and correlate the result with Events and the owning object. Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
Path Rules: failure boundary and production cost
Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge. The prerequisite contract is concrete: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests. A safe design limits blast radius, records the last good configuration, and uses kubectl get ingress shop -o yaml; kubectl describe ingress shop as a deterministic rollback checkpoint.
Capture the current state with kubectl get ingress shop -o yaml; kubectl describe ingress shop, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge.
How it works, step by step
Step 1 of 41. Define the reachability contract
Declare selectors, listeners, routes, or policy and keep endpoint readiness explicit: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
- Goal
- Route external HTTP traffic by host and path to backend Services.
- Owner
- Host Rules
When to use it & trade-offs
What it is
Route external HTTP traffic by host and path to backend Services. Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
Why it matters: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge. The invariant at risk is specific: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation. The quickest fact check before changing the design is kubectl get ingress shop -o yaml; kubectl describe ingress shop.
When to reach for it
- Use Host Rules to enforce this invariant: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
- Use Path Rules evidence from
kubectl get ingress shop -o yaml; kubectl describe ingress shopin reviews and incident timelines. Route external HTTP traffic by host and path to backend Services. - Choose the managed ingress or mesh route only when this cost is justified by governance or scale: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.
When to avoid or be careful
- Avoid assuming Host Rules is complete after YAML submission; the required behavior is concrete: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get ingress shop -o yaml; kubectl describe ingress shopfirst: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge. - Avoid adopting a heavier platform wrapper before measuring its cost: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.
Native, manual, and managed paths for Host Rules
kubectl get ingress shop -o yaml; kubectl describe ingress shop.Strengths: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
Watch out: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests. Recovery must also recognize this signal: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge.
kubectl get ingress shop -o yaml; kubectl describe ingress shop; the expected invariant is: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.Strengths: kubectl get ingress shop -o yaml; kubectl describe ingress shop gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike Host Rules, it does not make this symptom self-documenting: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge.
kubectl get ingress shop -o yaml; kubectl describe ingress shop.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
Watch out: The added platform ownership buys value at this cost: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
- Trace Host Rules to Backends through Path Rules; the invariant is: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
- Recognize the symptom: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge.
- Justify the cost: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.
- Verify with kubectl get ingress shop -o yaml; kubectl describe ingress shop instead of only inspecting YAML.
Benchmarks & rules of thumb
- 3
- pathTypes to know: Exact, Prefix, and ImplementationSpecific
- 1
- default backend can catch unmatched hosts or paths
- 404
- an edge symptom often caused by rule or backend mismatch
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the Host Rules owner contract: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation.
- Ignoring this telltale condition leads to unrelated changes: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge.
- Repeating
kubectl get ingress shop -o yaml; kubectl describe ingress shopwithout an owner for remediation wastes retry cost. Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation?
- Which owner object, logs, and Events would you inspect for this symptom-Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge-?
- At what threshold would this cost become unacceptable: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests?
kubectl get ingress shop -o yaml; kubectl describe ingress shop, name the failure, then justify the cost. Invariant: Ingress routing matches an incoming Host header and path, then forwards to a backend Service port; pathType Prefix or Exact controls interpretation. Failure: Overlapping prefix paths, wildcard expectations, missing rewrite annotations, or a wrong service port can route a request to the wrong backend or 404 at the edge. Cost: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Ingress Rules: Path-Based & Host-Based Routing with generative AI interview Q&A and hands-on practice.