Sign inSign up

riteshatri/replicaset

By riteshatri

•Updated 9 months ago

Image
0

239

riteshatri/replicaset repository overview

⁠☸️ Kubernetes ReplicaSet – Complete Hands-on Practical (v1 → v2 → v3)

This README is a step-by-step lab guide to understand how ReplicaSet works with images
and why ReplicaSet is NOT suitable for image rollout.

This lab uses 3 image versions to clearly show:

  • Image update ka koi effect nahi hota
  • Replica count change hota hai
  • New image tabhi aati hai jab pod delete hota hai

⁠🎯 Learning Objective

Is lab ke baad aap clearly samajh jaoge:

  • ReplicaSet kya karta hai
  • ReplicaSet kya nahi karta
  • Image update ka behaviour
  • Manual pod delete ka impact
  • ReplicaSet vs Deployment difference

⁠🐳 Docker Images Used (Already Built & Pushed)

docker push riteshatri/replicaset:v1
docker push riteshatri/replicaset:v2
docker push riteshatri/replicaset:v3

⚠️ NOTE: Har image me index.html alag hai taaki browser me clearly difference dikhe


⁠📁 Files Used in This Lab

FilePurpose
pod.yamlSimple pod test
replicaset.yamlReplicaSet definition
service.yamlPod expose karne ke liye

⁠📄 pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: ritpod
spec:
  containers:
  - name: ritcontainer
    image: riteshatri/replicaset:v2
    ports:
    - containerPort: 80

⁠📄 replicaset.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset
spec:
  replicas: 10
  selector:
    matchLabels:
      humhai: replicaset
  template:
    metadata:
      labels:
        humhai: replicaset
    spec:
      containers:
      - name: ritcontainer
        image: riteshatri/replicaset:v3
        ports:
        - containerPort: 80

⁠📄 service.yaml

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

⁠🔹 STEP 1: Pod Test (Optional – Basic Check)

kubectl get pods
kubectl apply -f pod.yaml
kubectl port-forward pod/ritpod 7417:80

👉 Browser open karo:

http://localhost:7417

⁠🔹 STEP 2: ReplicaSet Deploy (Image v1)

kubectl get pods
kubectl apply -f replicaset.yaml
kubectl get replicaset
kubectl get pods
kubectl get pods -o wide --show-labels

👉 Verify:

  • Pods running
  • Replicas = 3
  • Image = v1

⁠🔹 STEP 3: Create Service

kubectl get service
kubectl apply -f service.yaml
kubectl get service

Browser me open karo:

http://<EXTERNAL-IP>:<SERVICE-PORT>

Example:

http://40.127.217.237:6541

⁠🔹 STEP 4: Check Service ↔ Pod Mapping

kubectl get endpoints ritservice
kubectl get endpoints ritservice -o wide
kubectl describe service ritservice
kubectl describe endpoints ritservice

📌 Ye confirm karta hai ki:

  • Service kis-kis pod se connected hai
  • Total endpoints kitne hain

⁠🔹 STEP 5: Update Image v1 → v2 (IMPORTANT)

⁠Edit replicaset.yaml
image: riteshatri/replicaset:v2

Apply:

kubectl apply -f replicaset.yaml
kubectl get rs
kubectl get pods

⁠❌ OBSERVATION (MOST IMPORTANT PART)

  • Image update hui
  • ReplicaSet updated
  • Pods same old image (v1) pe hi chal rahe hain
  • Browser me koi change nahi

👉 ReplicaSet image rollout nahi karta


⁠🔹 STEP 6: Increase Replicas (3 → 6)

kubectl apply -f replicaset.yaml
kubectl get rs
kubectl get pods
⁠IMPORTANT:
  • New pods bane
  • New pods bhi v1 image ke hain
  • Browser output SAME

⁠🔹 STEP 7: Update Image v2 → v3

kubectl apply -f replicaset.yaml

👉 Ab bhi:

  • Koi change nahi
  • Pods still old image pe

⁠🔹 STEP 8: Manual Pod Delete (REAL MAGIC)

kubectl get pods
kubectl delete pod replicaset-2zfgb replicaset-75w95 replicaset-7qxn2

👉 Ab kya hoga:

  • Old pods delete hue ❌
  • ReplicaSet ne new pods banaye ✅
  • New pods me image = v3 🎉

Browser refresh karo 👇
👉 Ab NEW IMAGE dikhai degi


⁠📊 Final Behaviour Summary

ActionResult
Image update❌ No effect
Replica increase❌ Old image
Pod delete✅ New image
Service✅ Load balance

⁠🧠 ONE-LINE MEMORY TRICK

ReplicaSet = Pod count ka boss, Image ka nahi 😄


⁠🚨 Key Takeaways (Interview Ready)

✔ ReplicaSet pod count maintain karta hai
✔ Image rollout nahi karta
✔ Manual delete required
✔ Production ke liye suitable nahi
✔ Deployment is the solution


⁠🔜 Next Step

👉 Deployment (Recreate Strategy)
👉 Deployment (RollingUpdate Strategy)


⁠❤️ Author ❤️
Ritesh Sharma

Created for Kubernetes Hands-on Learning
Happy Learning ☸️🔥

Tag summary

Content type

Image

Digest

sha256:306d1442e…

Size

21.9 MB

Last updated

9 months ago

docker pull riteshatri/replicaset:v3