Kubernetes | Pod Vs ReplicatSets Vs Deployment

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.
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:
Create Pod
Kubectl run podname --image imagename
List pod
Kubectl get podsKubectl get poKubectl get pods -o wide
Login into pod
kubectl exec -it podname - sh
Delete Pod
Kubectl delete pod podnamekubectl delete pod pod1 pod2
Describe Pod
Kubectl describe pod podnameUpdate Pod
Kubectl edit pod podnameDry run command
kubectl run --image=nginx --dry-run=clientkubectl run --image=nginx --dry-run=client -o yamlkubectl run --image=nginx --dry-run=client -o yaml > podnew.ymlTroubleshoot pod
Kubectl logs podnameKubectl events podname
Declarative Method:
Create pod manifest file in
yamlformatpod-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:
Create replicaset
replicaset-manifest.yaml
kubectl apply -f replicaset-manifest.yaml
List Replicaset
kubectl get replicasetkubectl get rs
Describe replicaset
kubectl describe replicaset nginx-rsUpdate replicaset
kubectl replace-f replicaset-manifest.yamlDelete Replicaset
kubectl delete replicaset nginx-rsScale replicas: 3 ways
Kubectl scale rs/nginx-rs --replicas=5kubectl scale replicas=5 -f replicaset-manifest.yaml
Edit the yaml file and save
Kubectl edit rs/nginx-rsKubectl apply -f relicaset.yamlKubectl 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:
Create Deployment
deployment-manifest.yaml
kubectl apply -f deployment-manifest.yamlList deployment
kubectl get deploymentkubectl get all
Delete deployment
kubectl delete deploymentDescribe deployment
kubectl describe deployment nginx-deploy
Update image:
kubectl set image deploy/nginx-deploy nginx=nginx:1.20View rollout status
kubectl rollout status deployment/nginx-deployView rollout history
kubectl rollout history deployment/nginx-deploy
Rollback to previous version
kubectl rollout undo deployment/nginx-deploykubectl rollout undo deployment/nginx-deploy --recordRollback to specific revision
kubectl rollout undo deployment/nginx-deploy # to previous versionkubectl rollout undo deployment/nginx-deploy --to-revision=2Scaling:
# 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:
| Feature | Pod | ReplicaSet | Deployment |
| Purpose | Smallest deployable unit (1+ containers) | Ensures a fixed number of Pod replicas are running | Manages ReplicaSets for declarative updates and rollbacks |
| Managed by | Directly or by controllers (e.g., ReplicaSet, Deployment) | Directly or by Deployments | Directly 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 Case | Debugging, testing, or single-task containers | Legacy apps (rarely used directly) | Production stateless apps (e.g., web servers, APIs) |



