Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 51/ 160
03. Kubernetes Networking & Traffic Management

Ingress Rules: Path-Based & Host-Based Routing

Route external HTTP traffic by host and path to backend Services.

BeginnerHost Rules · Path Rules · Backends3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 shop and 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

Loading interactive 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.

Verify Path Rules, not only object creation

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.

Key takeaway: Host Rules is implemented only when this invariant remains observable: 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.

Recover from Path Rules drift

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.

Key takeaway: Accept the trade-off consciously: Declarative host/path rules are readable, but annotation-based rewrites and ordering remain controller-specific and require contract tests.

How it works, step by step

Step 1 of 4
Traffic author

1. 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.

Host Rules contract → owned state
Key numbers at this step
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 shop in 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 shop first: 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

Built-in API path
Best for: Route external HTTP traffic by host and path to backend Services. A concrete incident check is 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.

Datapath-specific extension
Best for: Quickly testing the Path Rules assumption with 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.

Managed ingress or mesh
Best for: Teams that need Backends integrated with guardrails; the evidence path is 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 shop without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Ingress Controllers (NGINX Ingress, Traefik, HAProxy)
Next topic
Automating SSL/TLS Certificates with cert-manager & Let's Encrypt