📖 Scenario: You are managing a web application running on Kubernetes. You want to update the application pods so that the old pods are completely terminated before new pods start. This is important to avoid conflicts during the update.
🎯 Goal: Create a Kubernetes Deployment manifest that uses the Recreate update strategy, which terminates all old pods before creating new ones.
📋 What You'll Learn
Create a Deployment named webapp in the default namespace
Use the image nginx:1.21 for the pods
Set the update strategy to Recreate
Set the number of replicas to 2
Expose the pods on container port 80
💡 Why This Matters
🌍 Real World
Using the Recreate update strategy is useful when your application cannot run multiple versions simultaneously or when you want to avoid conflicts during updates.
💼 Career
Understanding update strategies in Kubernetes is essential for DevOps engineers to manage application deployments safely and reliably.
Progress0 / 4 steps
1
Create the basic Deployment manifest
Create a Kubernetes Deployment manifest named webapp with 2 replicas using the image nginx:1.21. Set the container port to 80. Do not add the update strategy yet.
Kubernetes
Hint
Start by defining apiVersion, kind, metadata, and spec. Use replicas: 2 and set the container image to nginx:1.21. Don't add the update strategy yet.
2
Add the Recreate update strategy
Add the strategy field under spec and set its type to Recreate in the Deployment manifest.
Kubernetes
Hint
Under spec, add strategy: and set type: Recreate to specify the update strategy.
3
Apply the Deployment manifest
Use the kubectl apply -f deployment.yaml command to create the Deployment in the cluster. Assume the manifest is saved as deployment.yaml.
Kubernetes
Hint
Use kubectl apply -f deployment.yaml to create or update the Deployment from the YAML file.
4
Verify the update strategy
Run the command kubectl get deployment webapp -o jsonpath='{.spec.strategy.type}' to display the update strategy type of the webapp Deployment.
Kubernetes
Hint
This command extracts the update strategy type from the Deployment's spec. It should print Recreate.
Practice
(1/5)
1. What does the Recreate update strategy do in Kubernetes?
easy
A. Deletes old pods before creating new ones, causing downtime
B. Creates new pods first, then deletes old pods to avoid downtime
C. Updates pods one by one without deleting any
D. Scales pods up and down simultaneously during update
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 A
Quick Check:
Recreate = delete old pods first [OK]
Hint: Recreate means delete old pods first, then create new [OK]
Common Mistakes:
Confusing Recreate with RollingUpdate
Thinking Recreate avoids downtime
Assuming pods update one by one
2. Which YAML snippet correctly sets the update strategy to Recreate in a Deployment?
easy
A. strategy:\n type: RollingUpdate
B. strategy:\n type: Recreate
C. updateStrategy:\n type: Recreate
D. deploymentStrategy:\n type: Recreate
Solution
Step 1: Identify correct field name for update strategy
The correct field under Deployment spec is strategy with a nested type.
Step 2: Check correct value for Recreate
The value must be exactly Recreate to set that strategy.
Final Answer:
strategy:\n type: Recreate -> Option B
Quick Check:
strategy.type = Recreate [OK]
Hint: Use 'strategy.type: Recreate' exactly in Deployment spec [OK]
Common Mistakes:
Using wrong field names like updateStrategy or deploymentStrategy
Setting type to RollingUpdate instead of Recreate
Incorrect indentation or YAML syntax
3. Given this Deployment with strategy.type: Recreate, what happens when you update the container image?
medium
A. Pods update one by one without downtime
B. New pods start first, then old pods terminate, no downtime
C. All old pods are terminated before new pods start, causing downtime
D. Pods scale up and down simultaneously
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 C
Quick Check:
Recreate update = downtime during pod replacement [OK]
Hint: Recreate deletes old pods first, causing downtime on update [OK]
Common Mistakes:
Assuming pods update without downtime
Confusing with RollingUpdate behavior
Thinking pods update one by one
4. You set strategy.type: Recreate but notice pods are not deleted before new ones start. What is the likely issue?
medium
A. The Deployment has maxUnavailable set to 0, causing RollingUpdate behavior
B. The Deployment is using StatefulSet instead of Deployment
C. The pods have readinessProbe misconfigured
D. The strategy type is misspelled or incorrectly set
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 D