What You Will Learn
Beginner
- How Deployments work
- Scaling and updating
- Rolling updates and rollbacks
Deployment creates ReplicaSet which maintains desired Pod count
deployment.yamlyaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3 # Desired number of Pods
selector:
matchLabels:
app: my-app
template: # Pod template
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: nginx:1.25
ports:
- containerPort: 80Terminalbash
# Create
kubectl apply -f deployment.yaml
# Check
kubectl get deployments
kubectl get pods
# Scale to 5 replicas
kubectl scale deployment my-app --replicas=5
# Update image (rolling update)
kubectl set image deployment/my-app app=nginx:1.26
# Check rollout status
kubectl rollout status deployment/my-app
# Rollback if something went wrong
kubectl rollout undo deployment/my-app
# View rollout history
kubectl rollout history deployment/my-appRolling updates
When you update the image, K8s creates a new Pod, waits for it to be healthy, then kills an old Pod. Zero downtime! If the new version fails, rollback with one command.Practical Exercise
Create deployment.yaml with 3 replicas
Apply: kubectl apply -f deployment.yaml
Scale: kubectl scale deployment my-app --replicas=5
Update: kubectl set image deployment/my-app app=nginx:1.26
Rollback: kubectl rollout undo deployment/my-app
Key Takeaways
- Deployment manages a set of Pods (replicas).
- Scale: kubectl scale deployment X --replicas=N.
- Update: kubectl set image (triggers rolling update).
- Rollback: kubectl rollout undo (instant revert).
- Rolling update = zero downtime. Old Pods replaced one by one.
Comments
Comments
Post a Comment