AKS with Azure Load Balancer - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time to set up and manage an AKS cluster with an Azure Load Balancer changes as the number of services grows.
Specifically, how does adding more services affect the number of API calls and operations?
Analyze the time complexity of creating multiple services in AKS that use Azure Load Balancer.
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys
for i in range(1, n+1):
az aks service create --name service{i} --cluster-name myAKSCluster --load-balancer
This sequence creates an AKS cluster and then creates n services, each with its own Azure Load Balancer configuration.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating a service with a load balancer involves an API call to provision the load balancer and configure it.
- How many times: This happens once per service, so n times.
Each new service adds one load balancer provisioning operation, so the total operations grow directly with the number of services.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 load balancer provisioning calls |
| 100 | 100 load balancer provisioning calls |
| 1000 | 1000 load balancer provisioning calls |
Pattern observation: The number of operations grows linearly as the number of services increases.
Time Complexity: O(n)
This means the time to create and configure load balancers grows directly in proportion to the number of services.
[X] Wrong: "Adding more services does not increase load balancer provisioning time because Azure handles it automatically in the background."
[OK] Correct: Each service requires its own load balancer setup, which involves separate API calls and resource provisioning, so time grows with the number of services.
Understanding how resource provisioning scales helps you design efficient cloud architectures and explain your reasoning clearly in interviews.
What if we changed to using a single shared load balancer for all services? How would the time complexity change?
Practice
Solution
Step 1: Understand AKS and Load Balancer roles
AKS runs containerized apps, and Azure Load Balancer distributes traffic to these apps.Step 2: Identify the main function of Load Balancer
It balances incoming requests across pods to improve availability and scalability.Final Answer:
To distribute incoming network traffic evenly across multiple pods -> Option BQuick Check:
Load Balancer = traffic distribution [OK]
- Confusing Load Balancer with storage or monitoring
- Thinking Load Balancer builds container images
- Assuming Load Balancer manages pod resources
Solution
Step 1: Review Kubernetes service types
ClusterIP exposes service internally, NodePort exposes on node port, LoadBalancer creates cloud LB, ExternalName maps to external DNS.Step 2: Identify service type for Azure Load Balancer
Usingtype: LoadBalancertriggers Azure to provision a Load Balancer automatically.Final Answer:
LoadBalancer -> Option AQuick Check:
Service type LoadBalancer = Azure LB creation [OK]
- Choosing ClusterIP which is internal only
- Confusing NodePort with automatic LB creation
- Using ExternalName which is DNS mapping only
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: LoadBalancer
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
What happens when this service is applied?Solution
Step 1: Analyze service type and ports
Service type is LoadBalancer, so Azure LB is created. It listens on port 80 externally and forwards to targetPort 8080 on pods.Step 2: Understand traffic flow
External traffic on port 80 hits Azure LB, which routes it to pods' port 8080 matching selector app: myapp.Final Answer:
An Azure Load Balancer is created and routes port 80 traffic to pods on port 8080 -> Option AQuick Check:
LoadBalancer + port mapping = external traffic routing [OK]
- Thinking pods are exposed only internally
- Confusing NodePort with LoadBalancer
- Assuming traffic is blocked without explicit rules
type: LoadBalancer, but the external IP remains <pending> for a long time. What is the most likely cause?Solution
Step 1: Understand LoadBalancer IP allocation
Azure assigns an external IP when provisioning the Load Balancer. If quota is exceeded, IP remains pending.Step 2: Differentiate causes
Selector mismatch or pod ports cause traffic issues but do not block IP assignment. Cluster down would prevent service creation.Final Answer:
The Azure Load Balancer quota is exceeded in the subscription -> Option DQuick Check:
Pending IP often means quota limit reached [OK]
- Blaming selector mismatch for IP assignment delay
- Assuming pods not listening blocks IP allocation
- Thinking cluster down still allows service creation
Solution
Step 1: Choose correct service type for external exposure
type: LoadBalancercreates Azure LB to distribute traffic externally.Step 2: Enable autoscaling and health checks
Horizontal Pod Autoscaler adjusts pod count for traffic spikes; health probes ensure LB routes only to healthy pods.Step 3: Evaluate other options
ClusterIP is internal only; NodePort exposes ports but lacks automatic LB; ExternalName is DNS mapping, not load balancing.Final Answer:
Usetype: LoadBalancerservice, enable Horizontal Pod Autoscaler, and configure Azure Load Balancer health probes -> Option CQuick Check:
LoadBalancer + autoscale + health probes = high availability [OK]
- Using ClusterIP or ExternalName for external traffic
- Ignoring autoscaling for traffic spikes
- Not configuring health probes causing downtime
