What if your apps could fix themselves and never go down, even when you're not watching?
Why Kubernetes manages microservice deployment in Microservices - The Real Reasons
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have many small apps (microservices) that need to run together on different computers. You try to start each app by hand on each computer, making sure they talk to each other and stay running.
Doing this by hand is slow and confusing. Apps might crash and stay down, ports can clash, and updating one app means stopping many others. It's easy to make mistakes and hard to fix problems quickly.
Kubernetes acts like a smart manager that automatically starts, stops, and connects your microservices. It watches them all the time and fixes problems without you lifting a finger.
ssh server1
start serviceA
ssh server2
start serviceB
# Repeat for each service and serverkubectl apply -f microservices.yaml
kubectl get pods
# Kubernetes handles deployment and health checksWith Kubernetes, you can run many microservices reliably and scale them easily, freeing you to focus on building features instead of fixing deployments.
A company launches a shopping website with many microservices like payment, search, and user profiles. Kubernetes keeps all these services running smoothly, even during traffic spikes.
Manual deployment of microservices is slow and error-prone.
Kubernetes automates deployment, scaling, and recovery.
This leads to reliable, easy-to-manage microservice applications.
Practice
Solution
Step 1: Understand manual deployment challenges
Manually running many microservices is hard to keep track of and scale.Step 2: Role of Kubernetes in deployment
Kubernetes automates managing service lifecycles, scaling, and recovery to keep apps running smoothly.Final Answer:
Because it automates starting, stopping, and scaling services reliably -> Option BQuick Check:
Automation of service management = B [OK]
- Thinking Kubernetes replaces servers
- Believing Kubernetes writes app code
- Assuming Kubernetes handles only one service
service.yaml?Solution
Step 1: Identify the command to apply configuration files
Thekubectl apply -fcommand applies changes from a YAML file to the cluster.Step 2: Check other options for correctness
kubectl runis for running pods directly,kubectl startandkubectl createdo not accept YAML files directly.Final Answer:
kubectl apply -f service.yaml -> Option AQuick Check:
Apply YAML file = kubectl apply -f [OK]
- Using 'kubectl run' to deploy YAML files
- Trying 'kubectl start' which is invalid
- Confusing 'kubectl create' with applying configs
apiVersion: v1
kind: Pod
metadata:
name: myservice
spec:
containers:
- name: app
image: myapp:v1
ports:
- containerPort: 80
What will happen if the pod crashes unexpectedly?Solution
Step 1: Understand pod restart policy default
By default, Kubernetes restarts pods automatically if they crash to maintain service availability.Step 2: Check other options for correctness
Pods do not stay crashed without restart, nor are they deleted permanently without recreation, and restarts are not tied to image updates.Final Answer:
Kubernetes will automatically restart the pod to keep the service running -> Option CQuick Check:
Pod auto-restart on crash = D [OK]
- Thinking pods stay crashed until manual restart
- Believing pods delete permanently on crash
- Assuming restart depends on image updates
spec:
containers:
- name: app
image: myapp:v1
ports:
- containerPort: 80
restartPolicy: Never
What is the problem and how to fix it?Solution
Step 1: Identify restartPolicy effect
SettingrestartPolicy: Nevermeans Kubernetes will not restart the pod if it crashes.Step 2: Fix by changing restartPolicy
ChangingrestartPolicytoAlwayslets Kubernetes restart the pod automatically to keep it running.Final Answer:
The restartPolicy 'Never' stops restarts; change it to 'Always' to fix -> Option DQuick Check:
restartPolicy 'Always' enables auto-restart [OK]
- Changing port without checking crash cause
- Updating image version without error info
- Ignoring restartPolicy effect
Solution
Step 1: Understand high availability needs
Running multiple copies of a microservice ensures it stays available if some pods fail.Step 2: Use Kubernetes Deployment with replicas
A Deployment manages multiple pod replicas and automatically replaces failed pods to maintain availability.Final Answer:
Use a Deployment with replicas to run multiple pod copies for high availability -> Option AQuick Check:
Deployment + replicas = high availability [OK]
- Using single pod with no replicas
- Confusing ConfigMap with availability
- Mixing permissions with availability
