Kubernetes: How to Make Deployment to Update Image
Introduction
Updating the container image in a Kubernetes Deployment is a common task during application updates. In this guide, you'll learn how to use kubectl commands to update the image efficiently.
Prerequisites
Before proceeding, make sure:
- You have
kubectlinstalled and configured. - You have access to the Kubernetes cluster.
Updating the Image
Using kubectl set image
The kubectl set image command allows you to update the container image in a Deployment. Here's the syntax:
kubectl set image deployment/<deployment-name> <container-name>=<new-image>
Example
Suppose you have a Deployment named example-deployment with a container named example-container. To update the image to nginx:latest, run:
kubectl set image deployment/example-deployment example-container=nginx:latest
This updates the container image to nginx:latest.
Verify the Update
To verify the update, use:
kubectl rollout status deployment/<deployment-name>
Replace <deployment-name> with the name of your Deployment.
Rollback Changes
If the update causes issues, rollback to the previous version using:
kubectl rollout undo deployment/<deployment-name>
Best Practices
- Use Tags: Use versioned tags for images to avoid unexpected updates.
- Monitor Rollouts: Use
kubectl rollout statusto monitor updates. - Test Updates: Verify updates in a staging environment before deploying to production.
Conclusion
Updating the container image in a Kubernetes Deployment is straightforward with kubectl set image. By following these steps, you can ensure smooth and reliable application updates.
We earn commissions when you shop through the links below.
DigitalOcean
Cloud infrastructure for developers
Simple, reliable cloud computing designed for developers
DevDojo
Developer community & tools
Join a community of developers sharing knowledge and tools
Acronis
The most secure backup
Acronis: the most secure backup solution for your data
Pluralsight
Technology skills platform
Expert-led courses in software development, IT ops, data, and cybersecurity
Want to support DevOps Daily and reach thousands of developers?
Become a SponsorFound an issue?