Bird
Raised Fist0
Kubernetesdevops~5 mins

Recreate update strategy in Kubernetes - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sometimes you want to update your app by stopping the old version completely before starting the new one. The Recreate update strategy in Kubernetes does exactly that. It helps avoid conflicts by making sure only one version runs at a time.
When your app cannot run two versions at the same time because they share the same resources like files or ports.
When you want to avoid any chance of users connecting to two different versions during an update.
When your app needs a clean start without leftover data from the previous version.
When you want a simple update process without rolling multiple pods at once.
When you have a small app or low traffic and can afford a short downtime during updates.
Config File - deployment.yaml
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-app
  labels:
    app: example-app
spec:
  replicas: 2
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: example-app
  template:
    metadata:
      labels:
        app: example-app
    spec:
      containers:
      - name: example-app
        image: nginx:1.21
        ports:
        - containerPort: 80

This file defines a Deployment named example-app with 2 replicas.

The strategy.type: Recreate tells Kubernetes to stop all old pods before starting new ones during updates.

The selector and template.metadata.labels ensure the Deployment manages the correct pods.

The container runs the nginx:1.21 image on port 80.

Commands
This command creates the Deployment with the Recreate update strategy. It sets up the app pods as defined in the file.
Terminal
kubectl apply -f deployment.yaml
Expected OutputExpected
deployment.apps/example-app created
This command lists all pods with the label app=example-app to verify they are running.
Terminal
kubectl get pods -l app=example-app
Expected OutputExpected
NAME READY STATUS RESTARTS AGE example-app-6d4cfb6b7f-abcde 1/1 Running 0 10s example-app-6d4cfb6b7f-fghij 1/1 Running 0 10s
→
-l - Filter pods by label
This command updates the Deployment to use a new image version nginx:1.22, triggering the Recreate update strategy.
Terminal
kubectl set image deployment/example-app example-app=nginx:1.22
Expected OutputExpected
deployment.apps/example-app image updated
Check pods again to see that old pods are terminated before new pods start, confirming the Recreate strategy.
Terminal
kubectl get pods -l app=example-app
Expected OutputExpected
NAME READY STATUS RESTARTS AGE example-app-7f9d8c9d5f-klmno 1/1 Running 0 5s example-app-7f9d8c9d5f-pqrst 1/1 Running 0 5s
→
-l - Filter pods by label
Key Concept

If you remember nothing else from this pattern, remember: Recreate update strategy stops all old pods before starting new ones to avoid running multiple versions simultaneously.

Common Mistakes
Not specifying the update strategy, so Kubernetes uses RollingUpdate by default.
This causes old and new pods to run at the same time, which can cause conflicts if your app can't handle it.
Explicitly set strategy.type to Recreate in the Deployment spec to ensure old pods stop before new ones start.
Updating the Deployment image without checking pod status.
You might miss that pods are restarting or stuck, causing downtime or failed updates.
Always check pod status with kubectl get pods after updates to confirm the Recreate strategy worked.
Summary
Create a Deployment with strategy.type set to Recreate to control update behavior.
Apply the Deployment and verify pods are running with kubectl get pods.
Update the Deployment image to trigger the Recreate update, which stops old pods before starting new ones.
Check pods again to confirm the update completed with no overlapping versions.

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

  1. Step 1: Understand the Recreate strategy behavior

    The Recreate strategy deletes all old pods before starting new pods, which causes downtime.
  2. Step 2: Compare with other strategies

    Other strategies like RollingUpdate create new pods before deleting old ones to avoid downtime, unlike Recreate.
  3. Final Answer:

    Deletes old pods before creating new ones, causing downtime -> Option A
  4. 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

  1. Step 1: Identify correct field name for update strategy

    The correct field under Deployment spec is strategy with a nested type.
  2. Step 2: Check correct value for Recreate

    The value must be exactly Recreate to set that strategy.
  3. Final Answer:

    strategy:\n type: Recreate -> Option B
  4. 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

  1. Step 1: Understand Recreate update behavior on image change

    When the image changes, Recreate deletes all old pods before creating new pods.
  2. Step 2: Recognize downtime impact

    Because old pods are deleted first, there is downtime until new pods are ready.
  3. Final Answer:

    All old pods are terminated before new pods start, causing downtime -> Option C
  4. 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

  1. 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.
  2. Step 2: Rule out other causes

    maxUnavailable affects RollingUpdate, readinessProbe affects pod readiness, and StatefulSet is a different resource type.
  3. Final Answer:

    The strategy type is misspelled or incorrectly set -> Option D
  4. Quick Check:

    Misspelled strategy.type causes default RollingUpdate [OK]
Hint: Check exact spelling of strategy.type: Recreate [OK]
Common Mistakes:
  • Assuming maxUnavailable affects Recreate
  • Ignoring YAML syntax errors
  • Confusing Deployment with StatefulSet
5. You have an app that cannot run multiple versions simultaneously. How do you configure the Deployment update strategy to avoid version conflicts?
hard
A. Set strategy.type: Recreate to delete old pods before new ones
B. Set strategy.type: RollingUpdate with maxSurge=1
C. Use kubectl rollout restart without changing strategy
D. Set strategy.type: BlueGreen for zero downtime

Solution

  1. Step 1: Identify app requirement

    The app cannot run multiple versions at the same time, so pods must not overlap.
  2. Step 2: Choose update strategy

    Recreate deletes old pods before creating new ones, ensuring no version overlap.
  3. Step 3: Rule out other options

    RollingUpdate allows overlapping versions, kubectl restart doesn't change strategy, BlueGreen is not a built-in Kubernetes strategy.
  4. Final Answer:

    Set strategy.type: Recreate to delete old pods before new ones -> Option A
  5. Quick Check:

    App needs no overlap = use Recreate [OK]
Hint: Use Recreate strategy to avoid running multiple versions [OK]
Common Mistakes:
  • Choosing RollingUpdate which allows overlap
  • Thinking kubectl restart changes update strategy
  • Assuming BlueGreen is a native Kubernetes strategy
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard