Ingress controllers (Nginx, Traefik) in Kubernetes - Time & Space Complexity
We want to understand how the work done by an Ingress controller grows as the number of incoming requests increases.
Specifically, how does processing time change when more requests or routes are handled?
Analyze the time complexity of this simplified Ingress controller request handling snippet.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /app1
pathType: Prefix
backend:
service:
name: app1-service
port:
number: 80
- path: /app2
pathType: Prefix
backend:
service:
name: app2-service
port:
number: 80
This Ingress defines two paths that the controller must check to route requests correctly.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Checking each incoming request against the list of defined paths.
- How many times: For each request, the controller checks paths one by one until it finds a match.
As the number of requests or paths grows, the controller does more checks per request.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 requests, 2 paths | About 20 path checks |
| 100 requests, 10 paths | About 1,000 path checks |
| 1000 requests, 100 paths | About 100,000 path checks |
Pattern observation: The total work grows roughly by multiplying requests and paths checked.
Time Complexity: O(r * p)
This means the time to process requests grows proportionally to the number of requests times the number of paths to check.
[X] Wrong: "The controller checks only one path per request, so time grows only with requests."
[OK] Correct: The controller must check paths in order until it finds a match, so more paths mean more checks per request.
Understanding how request routing scales helps you explain system behavior clearly and shows you can think about performance in real setups.
"What if the Ingress controller used a hash map to find paths instead of checking each one? How would the time complexity change?"
Practice
Solution
Step 1: Understand Ingress controller purpose
Ingress controllers manage how external users access services inside the Kubernetes cluster.Step 2: Identify correct function
Nginx and Traefik route incoming traffic to the right service based on rules.Final Answer:
To route external traffic to internal Kubernetes services -> Option DQuick Check:
Ingress controller = traffic router [OK]
- Confusing ingress controller with node management
- Thinking ingress stores images
- Mixing ingress with monitoring tools
Solution
Step 1: Recall correct annotation key for ingress class
The standard annotation to specify ingress controller is kubernetes.io/ingress.class.Step 2: Match correct value for Nginx
The value for Nginx ingress controller is "nginx".Final Answer:
kubernetes.io/ingress.class: "nginx" -> Option AQuick Check:
Annotation key = kubernetes.io/ingress.class [OK]
- Using wrong annotation keys
- Mixing Traefik and Nginx values
- Omitting quotes around values
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: "traefik"
spec:
rules:
- host: example.com
http:
paths:
- path: /app
pathType: Prefix
backend:
service:
name: app-service
port:
number: 80
What happens when a user visits http://example.com/app/page?Solution
Step 1: Analyze ingress rule for host and path
The rule matches host example.com and path prefix /app, so /app/page matches.Step 2: Check backend service and port
Requests matching the path are sent to app-service on port 80.Final Answer:
Traffic is routed to the app-service on port 80 -> Option CQuick Check:
Path prefix match routes traffic correctly [OK]
- Assuming pathType Prefix is invalid
- Ignoring host match requirement
- Thinking default backend handles matched paths
Solution
Step 1: Identify cause of routing failure
Ingress controller routes traffic only to Ingress resources with matching ingress.class annotation.Step 2: Apply correct annotation for Nginx
Adding kubernetes.io/ingress.class: "nginx" tells Nginx controller to manage this Ingress.Final Answer:
Add annotation kubernetes.io/ingress.class: "nginx" to the Ingress resource -> Option AQuick Check:
Ingress class annotation enables controller routing [OK]
- Changing service port without checking actual port
- Removing annotations disables routing
- Restarting API server does not fix ingress routing
webapp and api, on the same domain using Traefik ingress. The webapp should respond on / and api on /api. Which Ingress configuration correctly achieves this?Solution
Step 1: Understand routing requirements
Both services share the same domain; webapp on root path /, api on /api path.Step 2: Configure single Ingress with multiple paths and correct annotation
One Ingress resource with two paths and annotation kubernetes.io/ingress.class: "traefik" directs traffic properly.Final Answer:
Use one Ingress with two paths: / to webapp and /api to api service, with annotation kubernetes.io/ingress.class: "traefik" -> Option BQuick Check:
Multiple paths in one Ingress with correct class [OK]
- Using wrong ingress.class annotation for Traefik
- Creating multiple Ingresses without annotations
- Missing path for root service
Ready to prove it?
Pass the test and this pattern moves unknown
