Kubernetes Using Kubernetes Deployments for Stateless Workloads Created: 25 Jul 2026 Updated: 25 Jul 2026

Kubernetes Recreate Deployment Strategy

The Recreate deployment strategy is the simplest approach Kubernetes offers: it terminates all existing Pods before creating new ones. During the switch there is a brief period of downtime — no Pods are serving traffic until the new version starts.

While this sounds undesirable, certain workloads require it. If two versions of an application cannot run simultaneously — for example, because they hold exclusive locks on a database schema, a file, or a message queue — Recreate is the safest option. It guarantees that the old version is fully stopped before the new version starts.

Kubernetes Deployments default to the RollingUpdate strategy. To use Recreate you set spec.strategy.type: Recreate in the Deployment manifest.

Core Concepts

Step 1: How Recreate Works — The Sequence

  1. You update the Deployment (e.g., change the image tag).
  2. Kubernetes terminates all Pods in the current ReplicaSet.
  3. It waits until every old Pod has fully stopped (Terminated state).
  4. It creates a new ReplicaSet with the updated spec.
  5. New Pods start up and become Ready.

Between step 2 and step 5, zero Pods are serving traffic. The length of this downtime depends on how fast your application shuts down and starts up.

Step 2: When to Use Recreate

ScenarioUse Recreate?Reason
Database migration that requires exclusive accessYesOld and new versions would conflict on schema.
App holds an exclusive file lock or leaseYesTwo versions cannot hold the same lock simultaneously.
Incompatible message-queue consumer versionsYesOld consumer might misinterpret new message format.
Stateless web API with zero-downtime requirementNoUse RollingUpdate, Blue/Green, or Canary instead.
Development / staging environmentYesDowntime is acceptable; simpler and faster than rolling update.

Step 3: Recreate vs RollingUpdate

FeatureRecreateRollingUpdate
DowntimeYes (brief)No (zero-downtime)
Two versions running at the same timeNeverYes, during the rollout
Configurationstrategy.type: RecreateDefault — no config needed
Rollbackkubectl rollout undokubectl rollout undo
Extra resources during updateNone (old Pods are gone first)Yes (surge Pods overlap)

Step 4: Minimising Downtime

Even with Recreate you can reduce the gap:

  1. Fast shutdown: Handle SIGTERM gracefully. Close connections, flush buffers, and exit quickly. Keep terminationGracePeriodSeconds reasonable (default 30s).
  2. Fast startup: Optimise your .NET application startup. Use compiled ahead-of-time (AOT) or reduce dependency injection registration time.
  3. ReadinessProbe: Use a readiness probe so the Service does not send traffic until the new Pod is genuinely ready.

Step 5: The Manifest — Key Section

The only change compared to a normal Deployment is adding two lines under spec.strategy:

spec:
strategy:
type: Recreate

Note: when using Recreate, you do not set maxSurge or maxUnavailable — those parameters only apply to RollingUpdate.

Hands-On: Kubernetes Commands

Deploy the Application

kubectl apply -f notification-api-deployment.yaml

Verify the Strategy Type

kubectl describe deployment notification-api | Select-String "StrategyType"

Output should show StrategyType: Recreate.

Watch Pods During an Update

kubectl get pods -l app=notification-api -w

Open this in a separate terminal so you can observe the stop-then-start sequence in real time.

Trigger an Update (Change the Image Tag)

kubectl set image deployment/notification-api notification-api=myregistry.azurecr.io/notification-api:2.0

Check Rollout Status

kubectl rollout status deployment/notification-api

View Rollout History

kubectl rollout history deployment/notification-api

Rollback to Previous Version

kubectl rollout undo deployment/notification-api

Step-by-Step Example

Scenario 1: Initial Deployment

We have a .NET 10 Notification API that processes messages from a Service Bus queue. Only one version should consume messages at a time, so we use the Recreate strategy.

1. Apply the Deployment Manifest

apiVersion: apps/v1
kind: Deployment
metadata:
name: notification-api
labels:
app: notification-api
spec:
replicas: 3
strategy:
type: Recreate
selector:
matchLabels:
app: notification-api
template:
metadata:
labels:
app: notification-api
spec:
containers:
- name: notification-api
image: myregistry.azurecr.io/notification-api:1.0
ports:
- containerPort: 8080
env:
- name: ASPNETCORE_URLS
value: "http://+:8080"
- name: NOTIFICATION_QUEUE_CONNECTION
value: "Endpoint=sb://notifications.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey"
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
readinessProbe:
httpGet:
path: /healthz/ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz/live
port: 8080
initialDelaySeconds: 10
periodSeconds: 15
kubectl apply -f notification-api-deployment.yaml

2. Verify All 3 Pods Are Running

kubectl get pods -l app=notification-api

You should see 3 Pods in Running state.

Scenario 2: Updating with Recreate

A new version (2.0) changes the message schema. Running 1.0 and 2.0 side by side would cause deserialization errors, so Recreate is the correct strategy.

3. Open a Watch Window

kubectl get pods -l app=notification-api -w

4. Update the Image

kubectl set image deployment/notification-api notification-api=myregistry.azurecr.io/notification-api:2.0

5. Observe the Sequence

In the watch window you will see:

  1. All 3 old Pods move to Terminating simultaneously.
  2. Once all 3 are gone, 3 new Pods appear in ContainerCreating state.
  3. New Pods transition to Running as the containers start.

During the gap between steps 1 and 3, the application is unavailable. For our Notification API consuming from a queue, this is acceptable — messages wait in the queue until the new Pods are ready.

Scenario 3: Rollback

If the new version has a bug, roll back. This also uses the Recreate pattern — old Pods are terminated first, then the previous version is recreated.

6. Undo the Rollout

kubectl rollout undo deployment/notification-api

7. Confirm the Rollback

kubectl describe deployment notification-api | Select-String "Image"

The image should show notification-api:1.0 again.

Summary

  1. Recreate terminates all old Pods before creating new ones—there is a brief downtime window.
  2. Set spec.strategy.type: Recreate in the Deployment manifest. Do not set maxSurge or maxUnavailable.
  3. Use Recreate when two versions cannot coexist — exclusive locks, incompatible schemas, or shared resources that do not support concurrent access.
  4. Minimise downtime by handling SIGTERM quickly, optimising startup, and using readiness probes.
  5. Rollback works the same as RollingUpdate: kubectl rollout undo.
  6. For workloads that need zero downtime, use RollingUpdate, Blue/Green, or Canary instead.


Share this lesson: