Updating Deployments
What you'll learn: How to safely update running applications in Kubernetes by modifying Deployment configurations.
Now that you've learned how Deployments manage replicas, it's time to explore one of their most powerful features: rolling updates. When you need to deploy a new version of your application—whether it's a new container image, updated environment variables, or different resource limits—Deployments handle the transition automatically without downtime.
How Rolling Updates Work
When you change the pod template in a Deployment (the part that defines what containers run), Kubernetes doesn't just delete all the old pods and create new ones. Instead, it performs a rolling update: gradually replacing old pods with new ones, ensuring your application stays available throughout the process.
Think of it like renovating a restaurant one table at a time while customers continue dining—not closing the entire restaurant for weeks.
Updating the Container Image
The most common update is changing the container image version. You can modify your Deployment YAML file and reapply it, or use kubectl directly:
kubectl set image deployment/my-app my-container=my-image:v2
Kubernetes will:
- Create new pods with the updated image
- Wait for them to become ready
- Gradually terminate old pods
- Continue until all replicas run the new version
Other Pod Template Changes
Any modification to the pod template triggers a rolling update:
- Environment variables
- Resource requests/limits
- Volume mounts
- Command arguments
Key Takeaway: Deployments enable zero-downtime updates by performing rolling updates whenever you change the pod template, automatically replacing old pods with new ones in a controlled, gradual manner.