Pods, ReplicaSets & Deployments · Part 1616

Replication Controllers & Replica SetsPod Replication, Self-Healing ও Scaling

Controller কীভাবে Desired Number of Pods Maintain করে: Reconciliation Loop, Replicas, Self-Healing, Labels ও Selectors, Pod Template, তারপর ReplicaSet Create, Scale ও Delete করা।

A ReplicaSet with replicas: 3 and a selector app=myapp keeping three Pods running: one Pod is deleted and the ReplicaSet creates a replacement from its Pod template
FIG. 16 Desired 3, Actual 2 → একটি নতুন Pod। ReplicaSet সবসময় Desired Count-এ ফেরত আনে।

আগের Tutorials-এ আমরা শিখেছি Kubernetes Pod কী, কীভাবে Pod Create করতে হয় এবং YAML Definition File ব্যবহার করে Kubernetes Resources Manage করা যায়।

কিন্তু একটি গুরুত্বপূর্ণ প্রশ্ন থেকে যায়।

ধরো, তোমার একটি Web Application Kubernetes-এর মধ্যে Run করছে।

Application-এর জন্য একটি Pod রয়েছে।

Pod 1 → Web Application

এখন কোনো কারণে Pod-টি Fail করল।

তাহলে কী হবে?

যদি এটি একটি Standalone Pod হয় এবং সেটি Delete হয়ে যায় বা Node Permanently Unavailable হয়ে যায়, তাহলে Application Unavailable হয়ে যেতে পারে।

এই Problem Solve করার জন্য Kubernetes-এ Controllers ব্যবহার করা হয়।

এই Tutorial-এ আমরা দুটি গুরুত্বপূর্ণ Controllers সম্পর্কে শিখব:

  • ReplicationController
  • ReplicaSet

এগুলোর মূল কাজ হলো Desired Number of Pod Replicas Maintain করা।

1. Kubernetes Controller কী?

Kubernetes-এ Controller হলো এমন একটি Component, যেটি Kubernetes Resources-এর Current State Monitor করে এবং Desired State-এর সঙ্গে Match করানোর চেষ্টা করে।

ধরো, তুমি Kubernetes-কে বললে:

আমার Application-এর সবসময় তিনটি Pods থাকতে হবে।

এখন Controller Check করবে:

Desired State = 3 Pods
Current State = 3 Pods
Action        = Nothing

কিন্তু যদি একটি Pod Delete হয়ে যায়:

Desired State = 3 Pods
Current State = 2 Pods
Action        = Create 1 New Pod

এভাবে Controller Continuously Desired State Maintain করার চেষ্টা করে।

Controller Workflow

              Desired State
                 3 Pods
                    |
                    ▼
             Kubernetes Controller
                    |
                    ▼
              Check Actual State
                    |
             +------+------+
             |             |
             ▼             ▼
         3 Pods          2 Pods
             |             |
             ▼             ▼
         No Action     Create 1 Pod

এই Process-কে Kubernetes-এর Reconciliation Loop বলা হয়।

Controller বারবার Current State Observe করে এবং প্রয়োজন অনুযায়ী Action নেয়।

2. Application-এর Multiple Replicas কেন দরকার?

ধরো, তোমার একটি NGINX Web Application রয়েছে।

এখন সেটি একটি Pod-এর মধ্যে Running।

Kubernetes Cluster
        |
        ▼
      Pod 1
        |
        ▼
   Web Application

এই Pod Unavailable হয়ে গেলে Application-এর Availability Problem হতে পারে।

এখন যদি একই Application-এর তিনটি Replicas Run করো:

    Kubernetes Cluster
            |
    +-------+-------+
    |       |       |
    ▼       ▼       ▼
  Pod 1   Pod 2   Pod 3
    |       |       |
    ▼       ▼       ▼
   App     App     App

তাহলে একটি Pod Fail করলেও অন্য Pods Application Serve করতে পারে।

এতে Application-এর High Availability Improve করা সম্ভব।

High Availability কী?

High Availability মানে Application এমনভাবে Design করা, যাতে একটি Component Fail হলেও Service যতটা সম্ভব Available থাকে।

তবে শুধু Multiple Pods থাকলেই Complete High Availability নিশ্চিত হয় না।

এর জন্য Service Routing, Readiness Checks এবং Multiple Nodes-এর মতো বিষয়ও গুরুত্বপূর্ণ।

3. Replica কী?

Replica হলো একই Application Run করা একটি Pod Instance।

ধরো, তোমার Application Image হলো:

nginx

এখন তুমি তিনটি Replicas Run করতে চাও।

এর অর্থ:

Replica 1 → NGINX Pod
Replica 2 → NGINX Pod
Replica 3 → NGINX Pod

অর্থাৎ:

3 Replicas = একই Application-এর 3 Pod Instances।

Example

  Deployment / ReplicaSet
            |
            ▼
       replicas: 3
            |
    +-------+-------+
    |       |       |
    ▼       ▼       ▼
  Pod 1   Pod 2   Pod 3
    |       |       |
  NGINX   NGINX   NGINX

Kubernetes Controller Desired Replica Count Maintain করার চেষ্টা করে।

4. ReplicationController কী?

ReplicationController হলো Kubernetes-এর একটি Controller, যার কাজ হলো নির্দিষ্ট সংখ্যক Pods Maintain করা।

ধরো, Configuration-এ লেখা রয়েছে:

replicas: 3

এর অর্থ Kubernetes তিনটি Matching Pods Maintain করার চেষ্টা করবে।

Example

Desired Replicas: 3
Actual Pods:      2
Missing Pods:     1

ReplicationController তখন একটি নতুন Pod Create করবে।

Before:
  Pod 1 → Running
  Pod 2 → Running
  Pod 3 → Deleted

After:
  Pod 1 → Running
  Pod 2 → Running
  Pod 4 → Created

এখানে নতুন Pod Create করে Desired Replica Count Restore করা হচ্ছে।

শুধু Scaling-এর জন্য Controller দরকার?

না।

ধরো, তুমি মাত্র একটি Pod Run করতে চাও।

replicas: 1

এখন সেই Pod Delete হয়ে গেলে Controller Replacement Pod Create করতে পারে।

এটিকে বলা হয় Self-Healing।

Self-Healing Example

Desired State
    |
    ▼
  1 Pod
    |
    ▼
Pod Deleted
    |
    ▼
Controller Detects Difference
    |
    ▼
New Pod Created

তাই ReplicationController শুধু Scaling নয়, Pod Replacement-এর জন্যও Useful।

5. Load Sharing এবং Scaling

Application-এর Traffic বাড়লে একটি Pod সব Requests Handle করতে নাও পারে।

তখন আরও Replicas Create করা যায়।

Before Scaling

Node 1
  |
  └── Pod 1
        |
        ▼
     Web App

After Scaling

Node 1
  |
  ├── Pod 1 → Web App
  |
  ├── Pod 2 → Web App
  |
  └── Pod 3 → Web App

এখন একই Application-এর তিনটি Pods Running।

যদি Node 1-এর Available Resources যথেষ্ট না থাকে, Kubernetes অন্য Suitable Nodes-এ Pods Schedule করতে পারে।

Multi-Node Example

            Kubernetes Cluster
                    |
         +----------+----------+
         |                     |
         ▼                     ▼
       Node 1                Node 2
         |                     |
     +---+---+             +---+---+
     |       |             |       |
     ▼       ▼             ▼       ▼
   Pod 1   Pod 2         Pod 3   Pod 4
     |       |             |       |
    App     App           App     App

এভাবে Application Workloads Cluster-এর Multiple Nodes-এর মধ্যে Distribute করা যায়।

Important: ReplicaSet নিজে HTTP Traffic Load Balance করে না। Traffic Matching Pods-এর মধ্যে Distribute করার জন্য সাধারণত Kubernetes Service ব্যবহার করা হয়।

6. ReplicationController vs ReplicaSet

ReplicationController এবং ReplicaSet-এর Main Goal একই।

Desired Number of Matching Pods Maintain করা।

তবে দুটির মধ্যে কিছু পার্থক্য রয়েছে।

FeatureReplicationControllerReplicaSet
TechnologyOlderNewer
API Versionv1apps/v1
SelectorOptional / Inferred হতে পারেExplicitly Required
Label MatchingEquality-basedEquality ও Set-based
Modern UsageRareCommonly Used
Recommended ApproachLegacy WorkloadsUsually through Deployment

ReplicaSet ReplicationController-এর তুলনায় More Flexible Label Selectors Support করে।

Modern Kubernetes Environment-এ আমরা সাধারণত সরাসরি ReplicaSet Create করার পরিবর্তে Deployment ব্যবহার করি।

কারণ Deployment নিজেই ReplicaSet Manage করে।

Deployment
    |
    ▼
ReplicaSet
    |
    ▼
   Pods

তবে ReplicaSet কীভাবে কাজ করে তা বোঝা Kubernetes-এর Internal Architecture শেখার জন্য গুরুত্বপূর্ণ।

7. ReplicationController YAML Structure

ReplicationController Definition File-এর চারটি Main Sections হলো:

apiVersion: v1
kind: ReplicationController
metadata:
spec:

এবার একটি Complete Example দেখি।

rc-definition.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: myapp-rc
  labels:
    app: myapp
    type: frontend
spec:
  replicas: 3
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: frontend
    spec:
      containers:
        - name: nginx-container
          image: nginx

এই YAML File Kubernetes-কে বলছে:

myapp-rc নামে একটি ReplicationController Create করো এবং myapp Application-এর তিনটি Matching Pods Maintain করো।

YAML Breakdown

FieldMeaning
apiVersion: v1Kubernetes API Version
kind: ReplicationControllerResource Type
metadata.nameController Name
metadata.labelsController-এর Labels
spec.replicasDesired Pod Replicas
spec.templatePod Creation Template
template.metadata.labelsCreated Pods-এর Labels
template.spec.containersContainer Configuration

ReplicationController Structure

ReplicationController
        |
        ├── apiVersion: v1
        |
        ├── kind: ReplicationController
        |
        ├── metadata
        |      |
        |      ├── name
        |      └── labels
        |
        └── spec
               |
               ├── replicas: 3
               |
               └── template
                       |
                       ├── metadata
                       |      |
                       |      └── labels
                       |
                       └── spec
                              |
                              └── containers
                                     |
                                     └── NGINX

8. Controller-এর Pod Template কেন দরকার?

ReplicationController অথবা ReplicaSet-কে জানতে হবে Replacement Pod কীভাবে Create করতে হবে।

এই Information template Field-এর মধ্যে Define করা হয়।

Example:

template:
  metadata:
    labels:
      app: myapp
  spec:
    containers:
      - name: nginx-container
        image: nginx

এই Template Kubernetes-কে বলে:

  • নতুন Pod-এর Labels কী হবে
  • কোন Container Image Run করবে
  • Container Name কী হবে

Example

ধরো, তিনটি Pods Running রয়েছে।

Pod 1 → Running
Pod 2 → Running
Pod 3 → Deleted

Controller Detect করল একটি Replica Missing।

এখন Controller Template ব্যবহার করে নতুন Pod Create করবে।

             Controller
                 |
                 ▼
            Pod Template
                 |
                 ▼
          Create New Pod
                 |
                 ▼
               Pod 4

Pod Template হলো নতুন Replacement Pod Create করার Blueprint।

Template-এর মধ্যে apiVersion ও kind লাগে?

ReplicationController বা ReplicaSet-এর template হলো Embedded Pod Template।

এখানে Pod-এর নিজস্ব Root-Level apiVersion এবং kind লিখতে হয় না।

কারণ Parent Controller Resource-এর spec.template ইতিমধ্যে Pod Template হিসেবে Defined।

9. ReplicaSet YAML Structure

ReplicaSet-এর YAML Structure ReplicationController-এর সঙ্গে অনেকটা Similar।

তবে এখানে দুটি গুরুত্বপূর্ণ Difference রয়েছে।

প্রথমত:

apiVersion: apps/v1
kind: ReplicaSet

দ্বিতীয়ত, ReplicaSet-এর জন্য Explicit Selector Define করতে হয়।

replicaset-definition.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-rs
  labels:
    app: myapp
    type: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
      type: frontend
  template:
    metadata:
      labels:
        app: myapp
        type: frontend
    spec:
      containers:
        - name: nginx-container
          image: nginx

এখানে Kubernetes একটি ReplicaSet Create করবে।

ReplicaSet তিনটি Matching Pods Maintain করার চেষ্টা করবে।

ReplicaSet Structure

ReplicaSet
    |
    ├── apiVersion: apps/v1
    |
    ├── kind: ReplicaSet
    |
    ├── metadata
    |
    └── spec
           |
           ├── replicas: 3
           |
           ├── selector
           |      |
           |      └── matchLabels
           |
           └── template
                  |
                  ├── metadata
                  |      |
                  |      └── labels
                  |
                  └── spec
                         |
                         └── containers

API Version কেন গুরুত্বপূর্ণ?

ReplicaSet-এর Correct API Version:

apiVersion: apps/v1

ভুল API Version ব্যবহার করলে Kubernetes Resource Recognize করতে নাও পারে।

যেমন ReplicaSet-এর জন্য apiVersion: v1 লিখলে এমন Error দেখা যেতে পারে:

no matches for kind "ReplicaSet" in version "v1"

তাই Resource Type অনুযায়ী Correct API Version ব্যবহার করা জরুরি।

10. Selectors এবং Labels কীভাবে কাজ করে?

ReplicaSet-এর অন্যতম গুরুত্বপূর্ণ Feature হলো Label Selector।

Selector ব্যবহার করে ReplicaSet নির্ধারণ করে কোন Pods তার Desired Replica Count-এর মধ্যে পড়বে।

Example:

selector:
  matchLabels:
    app: myapp
    type: frontend

এই Selector-এর অর্থ:

যেসব Pods-এর মধ্যে app=myapp এবং type=frontend Labels রয়েছে, সেগুলো Match করো।

Pod Template Labels

template:
  metadata:
    labels:
      app: myapp
      type: frontend

এখানে Pod Template-এর Labels ReplicaSet Selector-এর সঙ্গে Match করছে।

Selector Matching

ReplicaSet
    |
    ▼
Selector
    |
    ├── app: myapp
    |
    └── type: frontend
             |
             ▼
        Matching Pods
             |
      +------+------+
      |      |      |
      ▼      ▼      ▼
    Pod 1  Pod 2  Pod 3

এখানে তিনটি Pods-এর Labels Selector-এর সঙ্গে Match করছে।

Important Rule

ReplicaSet-এর Selector অবশ্যই Pod Template Labels-এর সঙ্গে Match করতে হবে।

যদি Selector এবং Template Labels Match না করে, ReplicaSet Definition Invalid হতে পারে।

11. Selectors কেন গুরুত্বপূর্ণ?

একটি Kubernetes Cluster-এ অনেক ধরনের Pods Running থাকতে পারে।

যেমন:

Frontend Pods
Backend Pods
Database Pods
Monitoring Pods
Logging Pods

এখন ReplicaSet-কে জানতে হবে কোন Pods তার Application-এর অংশ।

এই কাজ Labels এবং Selectors করে।

Example

Pod Labels:

labels:
  app: myapp

ReplicaSet Selector:

selector:
  matchLabels:
    app: myapp

এই Selector app=myapp Label থাকা Pods Match করবে।

Matching Logic

Pod Label
    |
    ▼
app=myapp
    |
    ▼
ReplicaSet Selector
    |
    ▼
app=myapp
    |
    ▼
Match

Important: Matching Labels থাকলেই ReplicaSet অন্য Controller-এর Pods Automatically Take Over করে না।

ReplicaSet Existing Pods Adopt করতে পারে যখন সেগুলো Matching এবং অন্য Controller-এর Ownership-এর অধীনে নেই।

12. ReplicaSet Existing Pods Manage করতে পারে?

হ্যাঁ।

ReplicaSet এমন Pods Adopt করতে পারে, যেগুলো আগে থেকেই Cluster-এ রয়েছে এবং Selector-এর সঙ্গে Match করে, যদি Ownership Rules সেটি Allow করে।

ধরো, Cluster-এ আগে থেকেই তিনটি Standalone Pods আছে।

Pod A → app=myapp
Pod B → app=myapp
Pod C → app=myapp

এখন একটি ReplicaSet Create করা হলো।

replicas: 3
selector:
  matchLabels:
    app: myapp

যদি Existing Pods অন্য Controller-এর অধীনে না থাকে এবং Selector Match করে, ReplicaSet সেগুলো Adopt করতে পারে।

তখন তিনটি Matching Pods আগে থেকেই থাকায় নতুন Pods Create করার প্রয়োজন নাও হতে পারে।

Example

Existing Pods
     |
     ├── Pod A
     ├── Pod B
     └── Pod C
           |
           ▼
       ReplicaSet
           |
           ▼
     Desired: 3 Pods
           |
           ▼
        No New Pod

কিন্তু পরবর্তীতে একটি Pod Delete হয়ে গেলে ReplicaSet Template ব্যবহার করে Replacement Pod Create করতে পারে।

এই কারণেই ReplicaSet-এর মধ্যে template Define করা জরুরি।

13. ReplicationController এবং ReplicaSet Create করা

এবার YAML Files ব্যবহার করে Controllers Create করার Commands দেখি।

ReplicationController Create করা

File Name:

rc-definition.yaml

Command:

kubectl create -f rc-definition.yaml

ReplicationControllers List করা

kubectl get replicationcontroller

Short Form:

kubectl get rc

ReplicaSet Create করা

File Name:

replicaset-definition.yaml

Command:

kubectl create -f replicaset-definition.yaml

ReplicaSets List করা

kubectl get replicaset

Short Form:

kubectl get rs

Pods Check করা

kubectl get pods

Example Output:

NAME             READY   STATUS    RESTARTS
myapp-rs-xxxxx   1/1     Running   0
myapp-rs-yyyyy   1/1     Running   0
myapp-rs-zzzzz   1/1     Running   0

ReplicaSet-created Pods সাধারণত Generated Names ব্যবহার করে।

এগুলোর Name প্রায়ই ReplicaSet-এর Name দিয়ে শুরু হয়।

14. ReplicaSet Scaling কীভাবে কাজ করে?

ধরো, আমাদের ReplicaSet-এর Configuration হলো:

replicas: 3

অর্থাৎ Kubernetes তিনটি Matching Pods Maintain করছে।

এখন Application Traffic বেড়ে গেছে।

তাই আমরা ছয়টি Pods Run করতে চাই।

ReplicaSet Scale করার দুটি Common Method রয়েছে।

Method 1: YAML Update করে Apply করা

প্রথমে YAML File Open করো।

আগের Configuration:

replicas: 3

এটি Change করো:

replicas: 6

তারপর:

kubectl apply -f replicaset-definition.yaml

এই Command Updated YAML Configuration Cluster-এ Apply করবে।

Before Scaling

ReplicaSet
    |
    ▼
replicas: 3
    |
    ├── Pod 1
    ├── Pod 2
    └── Pod 3

After Scaling

ReplicaSet
    |
    ▼
replicas: 6
    |
    ├── Pod 1
    ├── Pod 2
    ├── Pod 3
    ├── Pod 4
    ├── Pod 5
    └── Pod 6

Important: এখানে YAML File Manually Edit করার পর kubectl apply দিয়ে Cluster State Update করা হচ্ছে।

kubectl apply নিজে Local YAML File Edit করে না।

Method 2: kubectl scale ব্যবহার করা

YAML File Edit না করেও Live ReplicaSet Scale করা যায়।

File Reference দিয়ে Scale করা

kubectl scale --replicas=6 -f replicaset-definition.yaml

ReplicaSet Name দিয়ে Scale করা

kubectl scale --replicas=6 replicaset myapp-rs

এখানে Kubernetes Live ReplicaSet-এর Desired Replica Count ছয় করে দেবে।

গুরুত্বপূর্ণ Difference

kubectl scale Command Cluster-এর Live Object Update করে।

কিন্তু Local YAML File Automatically Update করে না।

ধরো, YAML File-এ এখনও রয়েছে:

replicas: 3

কিন্তু Cluster-এ Scale করা হয়েছে:

Desired Replicas: 6

এখন YAML File এবং Live Cluster Configuration-এর মধ্যে Difference তৈরি হয়েছে।

পরবর্তীতে Declarative Configuration Reconcile করার সময় Desired Replica Count আবার পরিবর্তিত হতে পারে।

তাই Git-based Configuration Management ব্যবহার করলে YAML File-ও Update করে রাখা ভালো।

15. ReplicaSet Delete করা

ReplicaSet Remove করতে:

kubectl delete replicaset myapp-rs

Default Behavior-এ Kubernetes ReplicaSet-এর Managed Pods-ও Delete করার চেষ্টা করে।

Workflow

Delete ReplicaSet
       |
       ▼
ReplicaSet Removed
       |
       ▼
Managed Pods Deleted

অর্থাৎ ReplicaSet Delete করলে সাধারণত তার Managed Pods-ও Delete হয়।

16. Useful Kubernetes Commands

CommandPurpose
kubectl create -f file.yamlYAML File থেকে Object Create
kubectl get rcReplicationControllers List
kubectl get rsReplicaSets List
kubectl get podsPods List
kubectl delete replicaset myapp-rsReplicaSet Delete
kubectl replace -f file.yamlExisting Object-এর Configuration Replace
kubectl apply -f file.yamlDeclarative Configuration Apply
kubectl scale --replicas=6 -f file.yamlFile Reference ব্যবহার করে Scale
kubectl scale --replicas=6 replicaset myapp-rsReplicaSet Name দিয়ে Scale

17. ReplicaSet-এর Simple Mental Model

ReplicaSet-কে একটি Supervisor হিসেবে ভাবতে পারো।

ধরো, তুমি Supervisor-কে বললে:

সবসময় তিনজন Workers Maintain করতে হবে।

Supervisor Check করছে:

Required Workers:  3
Available Workers: 3
Action:            Nothing

এখন একজন Worker চলে গেল।

Required Workers:  3
Available Workers: 2
Action:            Hire 1 New Worker

এটাই ReplicaSet-এর Main Concept।

Kubernetes Example

             ReplicaSet
                 |
                 ▼
           Desired: 3 Pods
                 |
                 ▼
            Actual: 2 Pods
                 |
                 ▼
          Create 1 New Pod
                 |
                 ▼
            Actual: 3 Pods

ReplicaSet-এর কাজ হলো Desired Number of Matching Pods Maintain করা।

18. ReplicaSet এবং Deployment-এর Relationship

আগের Tutorial-এ আমরা দেখেছি Deployment কীভাবে ReplicaSet ব্যবহার করে Pods Manage করে।

Modern Kubernetes-এ সাধারণত Application-এর জন্য সরাসরি ReplicaSet Create করার পরিবর্তে Deployment ব্যবহার করা হয়।

Architecture

   Kubernetes Deployment
            |
            ▼
        ReplicaSet
            |
            ▼
     Desired Replicas
            |
    +-------+-------+
    |       |       |
    ▼       ▼       ▼
  Pod 1   Pod 2   Pod 3
    |       |       |
    ▼       ▼       ▼
   App     App     App

Deployment Higher-Level Application Management Features Provide করে।

যেমন:

  • Replica Management
  • Rolling Updates
  • Rollbacks
  • Scaling

ReplicaSet মূলত Desired Number of Pods Maintain করে।

তাই Production Stateless Applications-এর জন্য Deployment Preferred।

Deployment vs ReplicaSet

FeatureReplicaSetDeployment
Maintain Pod ReplicasYesReplicaSet-এর মাধ্যমে
Pod ReplacementYesYes
Manual ScalingYesYes
Rolling UpdatesDirect Feature নয়Yes
Rollback SupportDirect Feature নয়Yes
Recommended for Stateless ApplicationsUsually IndirectlyYes

19. Complete Hands-on Example — ReplicaSet

এবার একটি ReplicaSet Create, Check, Scale এবং Delete করার Complete Workflow দেখি।

Step 1: YAML File Create করা

File Name:

replicaset-definition.yaml

YAML Configuration

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-rs
  labels:
    app: myapp
    type: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
      type: frontend
  template:
    metadata:
      labels:
        app: myapp
        type: frontend
    spec:
      containers:
        - name: nginx-container
          image: nginx

Step 2: ReplicaSet Create করা

kubectl create -f replicaset-definition.yaml

Step 3: ReplicaSet Check করা

kubectl get rs

Expected Example:

NAME       DESIRED   CURRENT   READY
myapp-rs   3         3         3

Step 4: Pods Check করা

kubectl get pods

Expected Example:

NAME             READY   STATUS
myapp-rs-xxxxx   1/1     Running
myapp-rs-yyyyy   1/1     Running
myapp-rs-zzzzz   1/1     Running

Step 5: ReplicaSet Scale করা

kubectl scale --replicas=6 replicaset myapp-rs

Step 6: Updated Replica Count Check করা

kubectl get rs

তারপর:

kubectl get pods

এখন ReplicaSet ছয়টি Pods Maintain করার চেষ্টা করবে।

Step 7: ReplicaSet Delete করা

kubectl delete replicaset myapp-rs

Testing শেষ হলে ReplicaSet এবং Managed Pods Remove হবে।

20. Final Takeaway — ReplicationControllers & ReplicaSets

এই Tutorial-এর Main Goal ছিল Kubernetes Controllers কীভাবে Desired Number of Pods Maintain করে তা বোঝা।

আমরা শিখেছি:

ReplicationController: Kubernetes-এর Older Controller, যা Desired Number of Pod Replicas Maintain করে।

ReplicaSet: Newer Controller, যা Labels এবং Selectors ব্যবহার করে Matching Pods Manage করে।

Replicas: একই Application-এর Multiple Pod Instances।

Self-Healing: Pod Missing হলে Controller Replacement Pod Create করে।

Scaling: Desired Replica Count Increase বা Decrease করা।

Selector: কোন Pods Controller Manage করবে তা Determine করে।

Template: নতুন Pod Create করার Blueprint।

Final Architecture

Kubernetes Controller
        |
        ▼
Desired State: 3 Pods
        |
        ▼
Check Current State
        |
        +------------------+
        |                  |
        ▼                  ▼
    3 Pods               2 Pods
        |                  |
        ▼                  ▼
    No Action         Create 1 Pod
                           |
                           ▼
                        3 Pods

Final Memory Rule

ReplicationController
         |
         ▼
Older Pod Replication Controller


ReplicaSet
         |
         ▼
Newer Pod Replication Controller
         |
         ▼
Labels + Selectors
         |
         ▼
Desired Pod Count


Deployment
         |
         ▼
ReplicaSet
         |
         ▼
Pods
         |
         ▼
Containers

Final One-Line Summary:

Kubernetes ReplicationController এবং ReplicaSet Desired Number of Pod Replicas Maintain করার জন্য ব্যবহার করা হয়। ReplicaSet হলো More Modern Controller, যা Labels এবং Selectors ব্যবহার করে Matching Pods Identify করে। Real Kubernetes Applications-এ সাধারণত Deployment ব্যবহার করা হয়, যা ReplicaSet-এর মাধ্যমে Pods Manage করে।

Official Documentation

মূল বিষয়: Kubernetes Controller-এর কাজ হলো Current State এবং Desired State-এর মধ্যে Difference Detect করে প্রয়োজনীয় Changes করা। ReplicaSet এই Mechanism ব্যবহার করে Application-এর Desired Number of Pods Maintain করে।

Was this guide helpful?

Search the archive

Press Esc to close