Kubernetes | Pod Vs ReplicatSets Vs Deployment

Pod:

In Kubernetes, a Pod is the smallest and simplest deployable unit. It represents a single instance of a running process (or group of tightly coupled processes) in a cluster. Here’s a breakdown of Pods:

Key Concepts of Pods:

1. Atomic Unit of Deployment

  • A Pod is the smallest deployable unit in Kubernetes.

  • It can contain one or more tightly coupled containers (usually one main container + optional sidecar containers).

2. Shared Resources

Containers in a Pod share:

  • The same network namespace (same IP & port space).

  • The same storage volumes (can access the same files).

  • The same Linux namespace (PID, UTS, IPC).

3. Lifecycle

  • Pods are ephemeral—they can be created, destroyed, and recreated dynamically.

  • If a Pod dies, Kubernetes can restart it (if configured) or replace it.

4. Managed by Controllers

  • Pods are typically managed by higher-level controllers like:

    • Deployments (for stateless apps)

    • StatefulSets (for stateful apps)

    • DaemonSets (for node-level agents)

    • Jobs/CronJobs (for batch processing)

5. Networking

  • Each Pod gets a unique cluster-internal IP.

  • Containers in a Pod communicate via localhost (since they share a network stack).

6. Storage

  • Pods can have Volumes (e.g., emptyDir, configMap, PersistentVolumeClaim) that are shared among containers.

Key Commands:

Imperative Method:

  1. Create Pod

    Kubectl run podname --image imagename

  2. List pod

    Kubectl get pods

    Kubectl get po

    Kubectl get pods -o wide

  3. Login into pod

    kubectl exec -it podname - sh

  4. Delete Pod

    Kubectl delete pod podname

    kubectl delete pod pod1 pod2

  5. Describe Pod

    Kubectl describe pod podname

  6. Update Pod

    Kubectl edit pod podname

  7. Dry run command

    kubectl run --image=nginx --dry-run=client

    kubectl run --image=nginx --dry-run=client -o yaml

    kubectl run --image=nginx --dry-run=client -o yaml > podnew.yml

  8. Troubleshoot pod

    Kubectl logs podname

    Kubectl events podname

Declarative Method:

  1. Create pod manifest file in yaml format

    pod-manifest.yaml

Kubectl create -f pod-manifest.yml or

Kubectl apply -f pod-manifest.yml

ReplicaSets:

In Kubernetes, a ReplicaSet is a workload controller that ensures a specified number of identical Pod replicas are running at all times. It is a replacement for the older ReplicationController, with added support for set-based label selectors.

Key Features of a ReplicaSet

1. Ensures High Availability

  • Maintains a stable set of Pods (e.g., always keeps 3 replicas running).

  • If a Pod crashes, the ReplicaSet creates a new one.

2. Load balancing &Scaling

  • You can manually scale up/down the number of replicas.

  • Pod can be deployed in multiple worker node for one replica

3. Self-Healing

  • If a node fails, the ReplicaSet reschedules Pods on healthy nodes.

4. Label-Based Selection

  • Uses selectors to identify which Pods it manages.

  • Supports both equality-based (`=, !=`) and set-based (`in, notin, exists`) selectors.

5. Not Meant for Direct Use

  • Typically managed by higher-level controllers like Deployments (which create and manage ReplicaSets for rolling updates).

Key Commands:

  1. Create replicaset

    replicaset-manifest.yaml

kubectl apply -f replicaset-manifest.yaml

  1. List Replicaset

    kubectl get replicaset

    kubectl get rs

  2. Describe replicaset

    kubectl describe replicaset nginx-rs

  3. Update replicaset

    kubectl replace-f replicaset-manifest.yaml

  4. Delete Replicaset

    kubectl delete replicaset nginx-rs

  5. Scale replicas: 3 ways

    Kubectl scale rs/nginx-rs --replicas=5

    kubectl scale replicas=5 -f replicaset-manifest.yaml

    Edit the yaml file and save

    Kubectl edit rs/nginx-rs

    Kubectl apply -f relicaset.yaml

    Kubectl replace -f replicaset.yaml

Deployment:

A Deployment is a high-level Kubernetes controller that manages ReplicaSets and provides declarative updates to Pods. It is the most common way to deploy and manage stateless applications in Kubernetes, offering features like rolling updates, rollbacks, and scaling.

Key Features of Deployments

1. Manages ReplicaSets

  • Creates and controls ReplicaSets, which in turn manage Pods.

  • Ensures the desired number of Pods are running (`replicas`).

2. Rolling Updates & Rollbacks

  • Updates Pods incrementally (zero downtime).

  • Can roll back to a previous version if something goes wrong.

3. Self-Healing & Scalability

  • Automatically replaces failed Pods.

  • Supports manual and automatic scaling (e.g., with HPA).

4. Declarative Updates

  • You define the desired state, and Kubernetes handles the rest.

Key Commands:

  1. Create Deployment

    deployment-manifest.yaml

    kubectl apply -f deployment-manifest.yaml

  2. List deployment

    kubectl get deployment

    kubectl get all

  3. Delete deployment

    kubectl delete deployment

  4. Describe deployment

    kubectl describe deployment nginx-deploy

  5. Update image:

    kubectl set image deploy/nginx-deploy nginx=nginx:1.20

  6. View rollout status

    kubectl rollout status deployment/nginx-deploy

  7. View rollout history

    kubectl rollout history deployment/nginx-deploy

  8. Rollback to previous version

    kubectl rollout undo deployment/nginx-deploy

    kubectl rollout undo deployment/nginx-deploy --record

  9. Rollback to specific revision

    kubectl rollout undo deployment/nginx-deploy # to previous version

    kubectl rollout undo deployment/nginx-deploy --to-revision=2

  10. Scaling:

    # Manual scaling

    kubectl scale deployment nginx-deploy --replicas=5

    # Auto-scaling (requires metrics server)

    kubectl autoscale deployment nginx-deploy --min=2 --max=10 --cpu-percent=80

Comparison:

FeaturePodReplicaSetDeployment
PurposeSmallest deployable unit (1+ containers)Ensures a fixed number of Pod replicas are runningManages ReplicaSets for declarative updates and rollbacks
Managed byDirectly or by controllers (e.g., ReplicaSet, Deployment)Directly or by DeploymentsDirectly by users (highest-level abstraction)
Scaling❌ No native scaling✅ Manual scaling (`kubectl scale`)✅ Manual + Auto-scaling (HPA)
Self-healing❌ No (unless restarted manually)✅ Replaces failed Pods automatically✅ Replaces failed Pods + manages rollbacks
Rolling Updates❌ No❌ No✅ Yes (zero-downtime updates)
Rollback❌ No❌ No✅ Yes (`kubectl rollout undo`)
Use CaseDebugging, testing, or single-task containersLegacy apps (rarely used directly)Production stateless apps (e.g., web servers, APIs)
0
Subscribe to my newsletter

Read articles from Ilayaraja Veerakalai directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ilayaraja Veerakalai
Ilayaraja Veerakalai

DevOps Engineer with a strong background in Configuration Management and support roles, skilled in tools like AWS, Docker, Kubernetes, Terraform, and Ansible. I focus on automating processes, improving system performance, and making networks scalable and secure in cloud environments.