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?
Practice
Recreate update strategy do in Kubernetes?Solution
Step 1: Understand the Recreate strategy behavior
The Recreate strategy deletes all old pods before starting new pods, which causes downtime.Step 2: Compare with other strategies
Other strategies like RollingUpdate create new pods before deleting old ones to avoid downtime, unlike Recreate.Final Answer:
Deletes old pods before creating new ones, causing downtime -> Option AQuick Check:
Recreate = delete old pods first [OK]
- Confusing Recreate with RollingUpdate
- Thinking Recreate avoids downtime
- Assuming pods update one by one
Recreate in a Deployment?Solution
Step 1: Identify correct field name for update strategy
The correct field under Deployment spec isstrategywith a nestedtype.Step 2: Check correct value for Recreate
The value must be exactlyRecreateto set that strategy.Final Answer:
strategy:\n type: Recreate -> Option BQuick Check:
strategy.type = Recreate [OK]
- Using wrong field names like updateStrategy or deploymentStrategy
- Setting type to RollingUpdate instead of Recreate
- Incorrect indentation or YAML syntax
strategy.type: Recreate, what happens when you update the container image?Solution
Step 1: Understand Recreate update behavior on image change
When the image changes, Recreate deletes all old pods before creating new pods.Step 2: Recognize downtime impact
Because old pods are deleted first, there is downtime until new pods are ready.Final Answer:
All old pods are terminated before new pods start, causing downtime -> Option CQuick Check:
Recreate update = downtime during pod replacement [OK]
- Assuming pods update without downtime
- Confusing with RollingUpdate behavior
- Thinking pods update one by one
strategy.type: Recreate but notice pods are not deleted before new ones start. What is the likely issue?Solution
Step 1: Check strategy type correctness
If pods are not deleted first, the strategy type may be misspelled or set incorrectly, so Kubernetes defaults to RollingUpdate.Step 2: Rule out other causes
maxUnavailable affects RollingUpdate, readinessProbe affects pod readiness, and StatefulSet is a different resource type.Final Answer:
The strategy type is misspelled or incorrectly set -> Option DQuick Check:
Misspelled strategy.type causes default RollingUpdate [OK]
- Assuming maxUnavailable affects Recreate
- Ignoring YAML syntax errors
- Confusing Deployment with StatefulSet
Solution
Step 1: Identify app requirement
The app cannot run multiple versions at the same time, so pods must not overlap.Step 2: Choose update strategy
Recreate deletes old pods before creating new ones, ensuring no version overlap.Step 3: Rule out other options
RollingUpdate allows overlapping versions, kubectl restart doesn't change strategy, BlueGreen is not a built-in Kubernetes strategy.Final Answer:
Set strategy.type: Recreate to delete old pods before new ones -> Option AQuick Check:
App needs no overlap = use Recreate [OK]
- Choosing RollingUpdate which allows overlap
- Thinking kubectl restart changes update strategy
- Assuming BlueGreen is a native Kubernetes strategy
Ready to prove it?
Pass the test and this pattern moves unknown
