Recreate update strategy in Kubernetes - Time & Space Complexity
We want to understand how the time to update pods grows when using the Recreate update strategy in Kubernetes.
How does the number of pods affect the update duration?
Analyze the time complexity of this Kubernetes deployment update snippet using Recreate strategy.
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-deployment
spec:
replicas: 5
strategy:
type: Recreate
template:
metadata:
labels:
app: example
spec:
containers:
- name: example-container
image: example-image:v2
This deployment updates all pods by deleting old ones first, then creating new pods all at once.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Deleting all pods first, then creating all new pods.
- How many times: Once for each pod in the deployment (equal to the number of replicas).
As the number of pods increases, the total update time grows proportionally because pods are handled sequentially (all old pods deleted first, then all new pods created).
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 pod deletions and 10 pod creations sequentially |
| 100 | 100 pod deletions and 100 pod creations sequentially |
| 1000 | 1000 pod deletions and 1000 pod creations sequentially |
Pattern observation: The update time grows linearly as the number of pods increases.
Time Complexity: O(n)
This means the update time grows directly in proportion to the number of pods being updated.
[X] Wrong: "The update happens all at once, so time stays the same no matter how many pods there are."
[OK] Correct: With Recreate strategy, pods are updated sequentially, so more pods mean more time.
Understanding how update strategies affect time helps you explain deployment behaviors clearly and shows you grasp practical Kubernetes operations.
What if we changed the update strategy to RollingUpdate? How would the time complexity change?