What if your website could fix itself and grow without you lifting a finger?
Why Pods and deployments for services in Microservices? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have a website running on a single server. When traffic grows, you try to copy the website files manually to another server and start it there. You have to remember to update both servers every time you change the code. If one server crashes, your site goes down until you fix it.
Manually managing servers is slow and risky. You can forget to update one server, causing inconsistent behavior. Scaling up or down takes time and effort. If a server fails, you must fix it yourself, leading to downtime. This approach does not handle failures or traffic spikes well.
Pods and deployments automate running your services in containers. A pod groups your app and its helpers, running together. Deployments manage pods by creating, updating, and replacing them automatically. This means your service stays available, scales easily, and recovers from failures without manual work.
ssh server1 copy files start service ssh server2 copy files start service
kubectl apply -f deployment.yaml kubectl rollout status deployment/my-service
It enables reliable, scalable, and self-healing services that adapt automatically to changing demands.
A popular online store uses deployments to run multiple copies of its payment service. If one copy crashes, the deployment creates a new one instantly, so customers never face errors during checkout.
Manual server management is slow and error-prone.
Pods group containers to run together smoothly.
Deployments automate updates, scaling, and recovery.
Practice
Pod in a microservices architecture?Solution
Step 1: Understand what a Pod is
A Pod is the smallest deployable unit in Kubernetes that runs one or more containers together.Step 2: Differentiate Pod from other components
Deployments manage Pods, Services route traffic, and persistent storage is handled separately.Final Answer:
To run one or more containers together as a single unit -> Option BQuick Check:
Pod = container unit [OK]
- Confusing Pods with Deployments
- Thinking Pods handle networking
- Assuming Pods store data
Solution
Step 1: Identify correct kind and replicas field
Deployment kind is correct and replicas should be a number, here 3.Step 2: Check metadata and syntax
Metadata name is valid; 'replicas: three' is invalid because replicas must be numeric.Final Answer:
replicas: 3\nkind: Deployment\nmetadata:\n name: my-deployment -> Option CQuick Check:
Deployment with numeric replicas = correct YAML [OK]
- Using 'kind: Pod' instead of Deployment
- Setting replicas as a word instead of number
- Confusing Service with Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 4
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web-container
image: nginxSolution
Step 1: Read replicas count in Deployment spec
The replicas field is set to 4, meaning Kubernetes will maintain 4 Pods.Step 2: Understand Deployment behavior
Deployment automatically creates and manages the specified number of Pods.Final Answer:
4 Pods -> Option AQuick Check:
replicas = 4 Pods running [OK]
- Assuming only 1 Pod runs by default
- Thinking Pods need manual start
- Confusing nodes with Pod count
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-server
spec:
replicas: 3
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: backend
spec:
containers:
- name: api-container
image: myapi:latestSolution
Step 1: Compare selector and template labels
The selector uses label 'app: api' but the Pod template labels 'app: backend' which do not match.Step 2: Understand label matching importance
Deployment uses selector to manage Pods; mismatch means no Pods are controlled or created.Final Answer:
The selector labels do not match the Pod template labels -> Option DQuick Check:
Selector labels must match Pod labels [OK]
- Ignoring label mismatch
- Assuming image name causes no Pods
- Thinking replicas count blocks Pod creation
Solution
Step 1: Understand Deployment update strategy
Deployments support rolling updates that create new Pods and remove old Pods gradually.Step 2: Compare options for zero downtime
Manual deletion or scaling down causes downtime; creating new Deployment causes conflicts.Final Answer:
Update the Deployment with a new image version; Kubernetes creates new Pods and gradually replaces old ones -> Option AQuick Check:
Rolling update = zero downtime update [OK]
- Deleting Pods manually causing downtime
- Scaling to zero causes service interruption
- Creating new Deployment causes conflicts
