Module 4 :Pods, ReplicaSets & Multi-Container Pods

🔹 Content Outline
Introduction to Pods
Smallest deployable unit in Kubernetes
Pod lifecycle & states
YAML example of a single pod
ReplicaSets
Why ReplicaSets are needed
Ensuring high availability
Scaling pods using ReplicaSets
YAML example with replicas
Multi-Container Pods
Sidecar pattern (logging, monitoring)
Ambassador & Adapter patterns
Example of 2 containers in one pod (nginx + sidecar container)
Hands-On Examples
kubectl apply -f pod.yaml
kubectl scale rs myapp-rs --replicas=3
Example of multi-container pod
Troubleshooting Tips
Check pod logs:
kubectl logs pod-name
Describe pod for issues:
kubectl describe pod pod-name
Common errors (ImagePullBackOff, CrashLoopBackOff)
🔹 What is a Pod?
A Pod is the smallest deployable unit in Kubernetes.
It represents one or more containers that run together on a worker node.
All containers in a Pod share:
The same network namespace (same IP address & port space)
Storage volumes (if defined)
Communication through
localhost
👉 You don’t deploy containers directly in Kubernetes; you deploy Pods.
Example: Simple Nginx Pod
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx:latest
ports:
- containerPort: 80
Apply it:
kubectl apply -f nginx-pod.yaml
kubectl get pods
🔹 What is a ReplicaSet?
A ReplicaSet ensures a specified number of pod replicas are running at all times.
If a Pod crashes, ReplicaSet automatically replaces it.
It allows scaling up or down.
Example: ReplicaSet with 3 Nginx Pods
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-rs
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
Apply it:
kubectl apply -f nginx-rs.yaml
kubectl get rs
kubectl get pods
👉 Scale it dynamically:
kubectl scale rs nginx-rs --replicas=5
🔹 Multi-Container Pods
Sometimes you want multiple containers inside a single pod that work closely together. They share the same network & storage, and communicate via localhost
.
Common Patterns
Sidecar – helper container (e.g., log collector with main app)
Ambassador – proxy container to route traffic
Adapter – transforms data for the main container
Example: Multi-Container Pod (Nginx + Sidecar Logger)
apiVersion: v1
kind: Pod
metadata:
name: nginx-multicontainer
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
- name: sidecar
image: busybox
command: ["sh", "-c", "while true; do echo Sidecar logging...; sleep 5; done"]
Apply it:
kubectl apply -f multi-container.yaml
kubectl logs nginx-multicontainer -c sidecar
🔹 Troubleshooting Pods
Check logs:
kubectl logs pod-name
Describe pod for events:
kubectl describe pod pod-name
Common issues:
ImagePullBackOff
→ wrong image name or no registry accessCrashLoopBackOff
→ application keeps crashingPending
→ not enough resources
✅ Summary
Pod = smallest unit, runs 1+ containers.
ReplicaSet = keeps desired number of Pods running.
Multi-Container Pods = useful for patterns like Sidecars & Ambassadors.
Learned hands-on YAML + kubectl commands.
Subscribe to my newsletter
Read articles from DevOpsLaunchpad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
