Blue-green deployments in Kubernetes - Time & Space Complexity
When using blue-green deployments in Kubernetes, we want to know how the time to switch versions grows as the number of services or pods increases.
We ask: How does deployment time change when we add more pods or services?
Analyze the time complexity of the following Kubernetes deployment switch.
apiVersion: apps/v1
kind: Deployment
metadata:
name: green-deployment
spec:
replicas: 5
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: myapp:green
---
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
This snippet shows a green deployment with 5 pods and a service routing traffic to pods labeled "myapp".
Look for repeated actions during deployment switch.
- Primary operation: Updating each pod from old version to new version.
- How many times: Once per pod, so number of pods (replicas) times.
As you add more pods, the time to update all pods grows roughly in direct proportion.
| Input Size (n = pods) | Approx. Operations (pod updates) |
|---|---|
| 10 | 10 pod updates |
| 100 | 100 pod updates |
| 1000 | 1000 pod updates |
Pattern observation: Doubling pods doubles the update operations needed.
Time Complexity: O(n)
This means the deployment time grows linearly with the number of pods you have.
[X] Wrong: "Switching traffic between blue and green is instant and does not depend on pod count."
[OK] Correct: While traffic switch via service selector is fast, the actual pod updates and readiness checks take time proportional to how many pods must be updated.
Understanding how deployment time scales helps you design smooth updates and avoid downtime, a key skill in real-world Kubernetes operations.
What if we changed the deployment to update pods in batches instead of all at once? How would the time complexity change?