liveBook · Manning

Recreate strategy

As explained in Kubernetes in Action, Second Edition

The Recreate strategy is a deployment update strategy that replaces all existing application pods at once before creating the updated pods.

Recreate is a Kubernetes Deployment update strategy. When the Deployment’s Pod template changes, the controller deletes every old pod, waits for their containers to finish, and then creates the new pods. Service is briefly unavailable while the old pods terminate and before the new ones are ready. Choose Recreate when old and new application versions cannot run together and downtime is acceptable. section 15.2

Listing 15.2 Enabling the Recreate update strategy in a Deployment
...
spec:
  strategy:            #1
    type: Recreate     #1
  replicas: 3
  ...

Set `spec.strategy.type` to `Recreate` in the Deployment manifest. Recreate has no additional strategy options; without this setting, a Deployment defaults to RollingUpdate. section 15.2.1 section 15.2

Replace a three-pod application

With Recreate configured, change the Pod template’s container image from `luksa/kiada:0.5` to `luksa/kiada:0.6` and update its `ver` label to match. Run `kubectl get po -l app=kiada -L ver` to watch all three old pods terminate before three version 0.6 pods appear. `kubectl get rs -L ver` then shows the old ReplicaSet at zero replicas and the new one at three. section 15.2.1

Changing only the strategy does not start an update: the Pod template must change. Recreate also governs `kubectl rollout restart`, which deletes and replaces all of the Deployment’s pods rather than replacing them gradually. By contrast, RollingUpdate replaces pods in stages to maintain availability. section 15.2.1 section 15.2.6

How Kubernetes in Action, Second Edition covers it

How deep it goes
Walks through manifest configuration and a three-pod replacement, including pod and ReplicaSet observations; identifies no Recreate tuning options.
Examples
Uses a three-replica image upgrade from version 0.5 to 0.6, with pod and ReplicaSet status listings.
What it assumes
Starts with Deployment Pod-template updates, then introduces strategy configuration before showing update commands.
What you can do after
Operate/configure it by setting `spec.strategy.type` to `Recreate` and changing the Pod template to trigger replacement.
How it connects
Connects Deployment Pod templates, ReplicaSets, RollingUpdate, and rollout restart through pod replacement behavior.

Also explained in

Compare how 3 books explain Recreate strategy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.