Kubernetes provides many deployment strategies help in maintaining the desired state of the application. In the previous blog we have covered the overview of 4 deployment strategies in K8s:
- Rolling Update
- Recreate
- Canary
- Blue/Green
You may go through the Introduction to Kubernetes Deployment Strategies (Introduction to Kubernetes Deployment Strategies – Knoldus Blogs). So, In this Blog, we will discuss the recreate strategy in detail.
Recreate
Recreate is the simplest deployment strategy in K8s. A recreate deployment is basically recreating the deployment with the new changes.
As we can see in the diagram in this deployment strategy, we scale down the replicas of the previous version and then deploy the replicas of the new version.

The biggest drawback of this strategy of deployment is that there is a small window of downtime between the scaling down of previous version pods and deploying of the new version pods.
The below is a template for deployment using recreate strategy.
- We create deployment with recreate strategy by saving the template to a file
recreate.yaml
.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment-recreate
namespace: nginx-app
labels:
app: nginx-recreate
annotations:
description: "nginx deployment with recrete strategy"
spec:
selector:
matchLabels:
app: nginx-recreate
replicas: 4
strategy:
type: Recreate
template:
metadata:
name: nginx
labels:
app: nginx-recreate
spec:
containers:
- name: nginx
image: nginx:1.16-perl
ports:
- containerPort: 8080
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
- Then we create the deployment using
kubectl
command. This will bev1
of the app.
kubectl apply -f recreate.yaml
The Deployment resource is a wrapper for Replicaset. It uses Replicaset to maintain the desired state.
By default, every deployment resource uses rolling updates as deployments. For using recreate strategy, you can change .spec.strategy.type
to recreate
.
Check the pods and Replicaset
kubectl get pods --namespace nginx-app --show-labels
kubectl get replicasets
Check container image on first(v1) Replicaset (Replicaset name will be different)
kubectl describe replicaset nginx-deployment-recreate-6d47fc67d4
- For upgrading it to
v2
, we update the image of nginx from1.16-perl
to1.18.0-perl
usingkubectl
command.
kubectl set image deployment nginx-deployment-recreate nginx=nginx:1.18.0-perl
Check the pods and Replicaset
kubectl get pods --namespace nginx-app --show-labels
kubectl get replicasets
Check container image on new(v2) Replicaset (Replicaset name will be different from the v1 Replicaset)
kubectl describe replicaset nginx-deployment-recreate-7c26ef35g7
Steps
Behind the scenes, Kubernetes takes the following actions:
When using a Recreate deployment strategy in Kubernetes, the following actions occur.
- The Deployment resource created a ReplicaSet that uses nginx:1.16-perl as container image.
- The ReplicaSet created 4 pods using nginx:1.16-perl container image.
- The image in the deployment was changed to nginx:1.18.0-perl.
- The Kubernetes noticed this change and created a new ReplicaSet that uses nginx:1.18.0-perl.
- Kubernetes set the v1ReplicaSet using nginx:1.16-perl replica count to 0.
- The v1 ReplicaSet deleted all of its pods.
- Kubernetes changed the replica count on the v2 ReplicaSet to 4.
- The v2 ReplicaSet created 4 new pods all using nginx:1.18.0-perl container image.
- Update complete!
When to use
As we know the main drawback of using Recreate is having downtime between the scaling down of the first Replicaset and scaling up of the second Replicaset.
We can use this strategy:
- When having a small downtime is not an issue.
- When you can’t have two different version of application at same time.
Example code can be found on the following gist:
Template for deployment using the recreate strategy
References
- Kubernetes Deployment Strategy – Recreate – DEV Community
- Deployment Strategies – Deployments | Developer Guide | OpenShift Container Platform 3.7
- Six Strategies for Application Deployment – The New Stack



1 thought on “Introduction to Kubernetes Deployment Strategies – Part 23 min read”
Comments are closed.