GKE Ingress with Load Balancer in GCP - Time & Space Complexity
When using GKE Ingress with a Load Balancer, it's important to understand how the system handles incoming traffic as it grows.
We want to know how the processing time changes when more requests or services are added.
Analyze the time complexity of the following GKE Ingress setup commands.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
This snippet defines an Ingress resource routing traffic to a service through a Load Balancer.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: The Load Balancer processes each incoming request and routes it to the correct backend service.
- How many times: Once per incoming request, which can be many and grow with traffic.
As the number of incoming requests increases, the Load Balancer handles each one individually.
| Input Size (n requests) | Approx. Operations |
|---|---|
| 10 | 10 routing operations |
| 100 | 100 routing operations |
| 1000 | 1000 routing operations |
Pattern observation: The number of operations grows directly with the number of requests.
Time Complexity: O(n)
This means the processing time grows linearly with the number of incoming requests.
[X] Wrong: "Adding more backend services will slow down each request significantly."
[OK] Correct: The Load Balancer routes requests based on rules, so adding services does not increase time per request, only the total number of requests affects processing time.
Understanding how GKE Ingress and Load Balancers scale with traffic helps you design systems that handle growth smoothly and predict performance.
"What if we added caching at the Load Balancer level? How would the time complexity change?"
Practice
Solution
Step 1: Understand Ingress role in GKE
Ingress allows routing external traffic to multiple services inside the cluster using one IP.Step 2: Recognize Load Balancer function
The Load Balancer created by Ingress exposes a single external IP to route traffic.Final Answer:
To expose multiple services through a single external IP address -> Option BQuick Check:
Ingress + Load Balancer = Single IP for many services [OK]
- Thinking each pod gets its own IP
- Confusing internal DNS with external exposure
- Assuming Load Balancer creates multiple IPs
Solution
Step 1: Identify GKE Ingress annotation for Load Balancer
The annotation 'kubernetes.io/ingress.class: gce' tells GKE to use Google Cloud Load Balancer.Step 2: Differentiate from other ingress classes
'nginx' is for NGINX ingress controller, not GCP Load Balancer.Final Answer:
kubernetes.io/ingress.class: 'gce' -> Option CQuick Check:
Use 'gce' annotation for GCP Load Balancer [OK]
- Using 'nginx' instead of 'gce' annotation
- Confusing internal vs external load balancer annotations
- Using non-existent annotation keys
http://example.com/api?
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: "gce"
spec:
rules:
- host: example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
Solution
Step 1: Analyze path rules in Ingress
The rule for path '/api' with pathType Prefix directs matching requests to 'api-service'.Step 2: Understand default path routing
The path '/' with Prefix matches all other requests and routes them to 'web-service'.Final Answer:
Traffic to /api goes to api-service; all other paths go to web-service -> Option AQuick Check:
Specific path matches first, then default [OK]
- Assuming '/' path overrides /api
- Thinking all traffic goes to one service
- Believing Ingress rejects overlapping paths
kubernetes.io/ingress.class: nginx in GKE but no external IP is assigned. What is the likely cause?Solution
Step 1: Understand Ingress class annotation effect
Annotation 'nginx' tells GKE to use NGINX ingress controller, which does not create a GCP Load Balancer automatically.Step 2: Recognize Load Balancer creation requirements
Only 'gce' ingress class triggers Google Cloud Load Balancer creation with external IP.Final Answer:
GKE does not create a Google Cloud Load Balancer for 'nginx' ingress class -> Option AQuick Check:
'nginx' ingress needs separate controller, no auto Load Balancer [OK]
- Assuming 'nginx' creates GCP Load Balancer automatically
- Blaming missing service port for no IP
- Thinking cluster node labels affect Load Balancer creation
frontend and backend, on the same IP but different paths using GKE Ingress with a Load Balancer. Which YAML snippet correctly configures this?Solution
Step 1: Confirm correct annotation for GCP Load Balancer
Options A and D use 'kubernetes.io/ingress.class: gce', which is correct for GKE Load Balancer.Step 2: Check pathType and host usage
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: multi-service-ingress annotations: kubernetes.io/ingress.class: "gce" spec: rules: - host: example.com http: paths: - path: /frontend pathType: Prefix backend: service: name: frontend port: number: 80 - path: /backend pathType: Prefix backend: service: name: backend port: number: 80 uses 'Prefix' pathType with a host, ensuring precise routing for /frontend and /backend paths on example.com.Step 3: Identify deprecated or incorrect syntax
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: multi-service-ingress spec: rules: - host: "*" http: paths: - path: /frontend backend: serviceName: frontend servicePort: 80 - path: /backend backend: serviceName: backend servicePort: 80 uses deprecated 'serviceName' and 'servicePort' keys and lacks annotation; apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: multi-service-ingress annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: example.com http: paths: - path: /frontend pathType: Prefix backend: service: name: frontend port: number: 80 - path: /backend pathType: Prefix backend: service: name: backend port: number: 80 uses 'nginx' ingress class, not GCE; apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: multi-service-ingress annotations: kubernetes.io/ingress.class: "gce" spec: rules: - http: paths: - path: /frontend pathType: Prefix backend: service: name: frontend port: number: 80 - path: /backend pathType: Prefix backend: service: name: backend port: number: 80 is missing host and incomplete.Final Answer:
Option D correctly configures two services on same IP with prefix path matching and GCE Load Balancer -> Option DQuick Check:
Use 'gce' annotation + prefix paths + host for precise multi-service routing [OK]
- Using 'nginx' annotation instead of 'gce'
- Using deprecated serviceName/servicePort keys
- Not specifying host or using wrong pathType
Ready to prove it?
Pass the test and this pattern moves unknown
