0
0
Kubernetesdevops~5 mins

Ingress vs LoadBalancer Service decision in Kubernetes - Performance Comparison

Choose your learning style9 modes available
Time Complexity: Ingress vs LoadBalancer Service decision
O(n)
Understanding Time Complexity

When choosing between Ingress and LoadBalancer Service in Kubernetes, it's important to understand how their processing time grows as the number of requests or services increases.

We want to know how the system's work changes when more traffic or services are added.

Scenario Under Consideration

Analyze the time complexity of routing requests using an Ingress controller versus a LoadBalancer Service.


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
---
apiVersion: v1
kind: Service
metadata:
  name: app1-loadbalancer
spec:
  type: LoadBalancer
  selector:
    app: app1
  ports:
  - port: 80
    targetPort: 8080

This snippet shows an Ingress routing multiple paths to services and a LoadBalancer Service exposing a single app directly.

Identify Repeating Operations
  • Primary operation: Ingress controller checks each incoming request against its list of rules to find the matching path and service.
  • How many times: For each request, it may check multiple rules until it finds a match.
  • LoadBalancer Service: Directly routes requests to one service without rule checks.
  • Dominant operation: Ingress rule matching per request.
How Execution Grows With Input

As the number of Ingress rules grows, the controller checks more rules per request, increasing work.

Number of Rules (n)Approx. Checks per Request
10Up to 10 checks
100Up to 100 checks
1000Up to 1000 checks

Pattern observation: The work grows roughly in direct proportion to the number of rules.

Final Time Complexity

Time Complexity: O(n)

This means the time to route a request grows linearly with the number of Ingress rules.

Common Mistake

[X] Wrong: "Ingress routing time stays the same no matter how many rules exist."

[OK] Correct: Each request must be checked against rules until a match is found, so more rules mean more checks and longer processing time.

Interview Connect

Understanding how routing scales helps you design systems that handle growth smoothly. This skill shows you can think about system behavior beyond just writing code.

Self-Check

"What if the Ingress controller used a hash map for rules instead of checking them one by one? How would the time complexity change?"