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?
Practice
kubectl rollout undo deployment/myapp do in Kubernetes?Solution
Step 1: Understand the command purpose
The commandkubectl rollout undois used to revert a deployment to a previous state.Step 2: Apply to the given deployment
Usingdeployment/myappspecifies which deployment to rollback.Final Answer:
It rolls back the deployment 'myapp' to its previous version. -> Option BQuick Check:
Rollback command = revert deployment [OK]
- Confusing rollback with delete command
- Thinking it updates to latest version instead of previous
- Using scale command instead of rollback
Solution
Step 1: Recall correct rollback syntax
The correct command to rollback iskubectl rollout undo deployment/<name>.Step 2: Match syntax with deployment name
Replacing <name> with 'webapp' giveskubectl rollout undo deployment/webapp.Final Answer:
kubectl rollout undo deployment/webapp -> Option AQuick Check:
Correct rollback syntax = rollout undo [OK]
- Using 'rollback' instead of 'rollout undo'
- Incorrect order of words in command
- Missing 'deployment/' prefix
kubectl apply -f deployment-v1.yaml kubectl apply -f deployment-v2.yaml kubectl rollout undo deployment/myapp
What will be the current version of the deployment 'myapp' after the last command?
Solution
Step 1: Understand deployment updates
First, version 1 is applied, then version 2 updates the deployment.Step 2: Rollback command effect
The rollback command reverts the deployment to the previous version, which is version 1.Final Answer:
Version 1 (deployment-v1.yaml) -> Option AQuick Check:
Rollback reverts to last version before update [OK]
- Assuming rollback deletes deployment
- Thinking rollback keeps current version
- Confusing rollback with reapply
kubectl rollout undo deployment/myapp but got an error: error: no rollout found. What is the most likely cause?Solution
Step 1: Analyze the error message
The error 'no rollout found' means no previous rollout history exists for rollback.Step 2: Identify cause
This usually happens if the deployment was never updated or has only one version.Final Answer:
The deployment 'myapp' has no previous versions to rollback to. -> Option CQuick Check:
No rollout history = no rollback possible [OK]
- Assuming cluster is down causes this error
- Forgetting to check deployment name spelling
- Thinking rollback always works without history
Solution
Step 1: Recall rollback to specific revision syntax
The correct syntax to rollback to a specific revision iskubectl rollout undo deployment/<name> --to-revision=<number>.Step 2: Apply to 'api-server' and revision 2
Replacing placeholders giveskubectl rollout undo deployment/api-server --to-revision=2.Final Answer:
kubectl rollout undo deployment/api-server --to-revision=2 -> Option DQuick Check:
Use '--to-revision' flag to rollback specific version [OK]
- Using incorrect flags like --revision or wrong command order
- Omitting '--to-revision' flag
- Using 'rollback' instead of 'rollout undo'
Ready to prove it?
Pass the test and this pattern moves unknown
