This document is a step-by-step, beginner-friendly lab guide to clearly understand how Deployment Recreate Strategy works in Kubernetes.
You will perform 3 image-based practicals (v1, v2, v3) and visually experience downtime when images are updated.
By the end of this lab, you will understand:
We will use 3 versions of the same application:
docker push riteshatri/deploymentrecreate:v1
docker push riteshatri/deploymentrecreate:v2
docker push riteshatri/deploymentrecreate:v3
Each image shows different UI text so changes are clearly visible in browser.
| File Name | Purpose |
|---|---|
| deployment.yaml | Kubernetes Deployment (Recreate strategy) |
| service.yaml | Exposes application |
| index.html | Application UI (inside image) |
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploymentrecreate
spec:
# replicas: 10
replicas: 2
# replicas: 3
# replicas: 50
selector:
matchLabels:
humhai: recreate
template:
metadata:
labels:
humhai: recreate
spec:
containers:
- name: ritcontainer
image: riteshatri/deploymentrecreate:v1
# image: riteshatri/deploymentrecreate:v2
# image: riteshatri/deploymentrecreate:v3
ports:
- containerPort: 80
strategy:
type: Recreate
apiVersion: v1
kind: Service
metadata:
name: ritservice
spec:
selector:
humhai: recreate
ports:
- port: 6541
targetPort: 80
type: LoadBalancer
kubectl apply -f deployment.yaml
Check pods:
kubectl get pods
kubectl get deployment
β‘οΈ Pods should be Running
kubectl apply -f service.yaml
kubectl get service
Copy EXTERNAL-IP and PORT
Open browser:
http://<EXTERNAL-IP>:<PORT>
β You will see Deployment Recreate β Version 1
deployment.yamlChange image:
image: riteshatri/deploymentrecreate:v2
strategy:
type: Recreate
Apply update:
kubectl apply -f deployment.yaml
Immediately run:
kubectl get pods
You will notice:
β All OLD pods TERMINATED
β For some time NO pods running
β Website goes DOWN
β Browser shows error
β‘οΈ THIS IS DOWNTIME
After a few seconds:
kubectl get pods
β‘οΈ New pods start running
β‘οΈ Refresh browser
β Now Version-2 UI is visible
Recreate Strategy =
β Old pods deleted first
β Downtime occurs
β New pods created later
Edit deployment.yaml again:
image: riteshatri/deploymentrecreate:v3
Apply:
kubectl apply -f deployment.yaml
Refresh browser β Version-3 UI visible
| Image Version | What Happens |
|---|---|
| v1 | Initial deployment |
| v2 | Downtime + new pods |
| v3 | Downtime again + new pods |
β Recreate strategy deletes all pods first
β Guaranteed downtime
β Not safe for production
β Good only for learning
β Used rarely in real systems
Recreate = Pehle tod, phir bana π£
π Learn RollingUpdate Strategy
π Zero downtime deployments
π Blue-Green & Canary deployments
Created for Kubernetes Hands-on Learning
Happy Learning βΈοΈπ₯
Content type
Image
Digest
sha256:15b401f55β¦
Size
21.9 MB
Last updated
9 months ago
docker pull riteshatri/deploymentrecreate:v3