Rollback to previous version in Kubernetes - Time & Space Complexity
When rolling back a deployment in Kubernetes, it's important to know how the time to complete the rollback changes as the deployment size grows.
We want to understand how the rollback process scales with the number of pods or replicas.
Analyze the time complexity of this rollback command.
kubectl rollout undo deployment/my-app
This command tells Kubernetes to revert the deployment named "my-app" to its previous version.
What repeats during rollback?
- Primary operation: Kubernetes updates pods to the previous version, typically in batches or rolling updates.
- How many times: Once for each pod or replica in the deployment.
As the number of pods increases, the rollback takes longer because each pod must be updated.
| Input Size (pods) | Approx. Operations |
|---|---|
| 10 | 10 pod updates |
| 100 | 100 pod updates |
| 1000 | 1000 pod updates |
Pattern observation: The time grows directly with the number of pods to update.
Time Complexity: O(n)
This means the rollback time grows linearly with the number of pods in the deployment.
[X] Wrong: "Rollback happens instantly no matter how many pods there are."
[OK] Correct: Each pod must be updated separately, so more pods mean more work and more time.
Understanding how rollback time scales helps you explain deployment strategies and system behavior clearly in real work situations.
What if the rollback updated pods in parallel batches instead of one by one? How would the time complexity change?