Sign inSign up

riteshatri/deploymentrecreate

By riteshatri

β€’Updated 9 months ago

Image
0

297

riteshatri/deploymentrecreate repository overview

β πŸš€ Kubernetes Deployment – Recreate Strategy (Complete Practical Lab)

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.


⁠🧠 Learning Objective

By the end of this lab, you will understand:

  • What Recreate strategy is
  • Why downtime happens
  • How Kubernetes behaves when images are updated
  • Why Recreate strategy is not recommended for production
  • Why RollingUpdate exists

⁠🧩 Prerequisites

  • Kubernetes cluster (AKS / EKS / GKE / Minikube)
  • kubectl configured
  • Docker installed
  • Internet access (to pull images)
  • Basic understanding of Pods & Services

⁠🐳 Docker Images Used (Already Pushed)

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.


β πŸ“ Files Used in This Lab

File NamePurpose
deployment.yamlKubernetes Deployment (Recreate strategy)
service.yamlExposes application
index.htmlApplication UI (inside image)

β πŸ“„ deployment.yaml

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

β πŸ“„ service.yaml

apiVersion: v1
kind: Service
metadata:
  name: ritservice
spec:
  selector:
    humhai: recreate
  ports:
    - port: 6541
      targetPort: 80
  type: LoadBalancer

β πŸ”Ή STEP 1: Deploy Version-1 (Initial Setup)

⁠Apply Deployment (v1 image)
kubectl apply -f deployment.yaml

Check pods:

kubectl get pods  
kubectl get deployment

➑️ Pods should be Running


β πŸ”Ή STEP 2: Create Service

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


β πŸ”Ή STEP 3: Update Image to Version-2 (Recreate in Action)

⁠Edit deployment.yaml

Change image:

image: riteshatri/deploymentrecreate:v2
strategy:
  type: Recreate

Apply update:

kubectl apply -f deployment.yaml

⁠⚠️ IMPORTANT OBSERVATION (VERY IMPORTANT)

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


β πŸ”Ή STEP 4: New Pods Come Up

After a few seconds:

kubectl get pods

➑️ New pods start running
➑️ Refresh browser

βœ… Now Version-2 UI is visible


⁠🧠 CONCLUSION (Version-2)

Recreate Strategy =
❌ Old pods deleted first
❌ Downtime occurs
βœ… New pods created later


β πŸ”Ή STEP 5: Update Image to Version-3

Edit deployment.yaml again:

image: riteshatri/deploymentrecreate:v3

Apply:

kubectl apply -f deployment.yaml

⁠πŸ’₯ WHAT HAPPENS NOW?

  • All pods die ☠️
  • Website disappears ❌
  • Users see nothing 😡
  • After some time…
  • New pods start
  • Website comes back πŸŽ‰

Refresh browser β†’ Version-3 UI visible


β πŸ“Š Complete Image Flow Summary

Image VersionWhat Happens
v1Initial deployment
v2Downtime + new pods
v3Downtime again + new pods

⁠🚨 Key Takeaways (EXAM / INTERVIEW READY)

βœ” Recreate strategy deletes all pods first
βœ” Guaranteed downtime
βœ” Not safe for production
βœ” Good only for learning
βœ” Used rarely in real systems


⁠🧠 ONE-LINE MEMORY TRICK

Recreate = Pehle tod, phir bana πŸ’£


β πŸ”œ What Next?

πŸ‘‰ Learn RollingUpdate Strategy
πŸ‘‰ Zero downtime deployments
πŸ‘‰ Blue-Green & Canary deployments


⁠❀️❀️ Author ❀️❀️

RITESH SHARMA

Created for Kubernetes Hands-on Learning
Happy Learning ☸️πŸ”₯

Tag summary

Content type

Image

Digest

sha256:15b401f55…

Size

21.9 MB

Last updated

9 months ago

docker pull riteshatri/deploymentrecreate:v3