Using Kustomize’s image transformer simplifies the process of updating container images. This method ensures that all instances of the image in your manifests are consistently updated.
Changing the Image Name
To change the image from NGINX to another image (for example, HAProxy), update yourkustomization.yaml file with the following configuration. In this file, the name field specifies the target image to replace, while the newName field defines the new image.
nginx image and replaces them with haproxy. The transformed deployment will look like this:
Note: The container name defined in the deployment (in this case, web) is independent of the image transformer operation. The transformer only targets the image name mentioned in the kustomization file.
Changing the Image Tag
If you wish to update the image tag rather than the image name—for instance, changing the tag from the default to2.4—you can specify the newTag property in your kustomization.yaml file.
Start with the same original deployment:
kustomization.yaml file to include the new tag:
nginx:2.4:
Combining Image Name and Tag Updates
You can combine both the image name and tag updates in a single configuration. For example, to change the image from NGINX to HAProxy and update its tag to2.4, configure your kustomization.yaml as shown below:
nginx image to haproxy:2.4, resulting in the following deployment:
Conclusion
Leveraging Kustomize’s image transformer provides a flexible and efficient method to manage container images in your Kubernetes deployments. Whether you need to update the image name, tag, or both, this approach eliminates the need for manual edits across multiple files, ensuring consistency and reducing potential errors in your configuration. For more details on Kubernetes deployments and best practices, check out the following resources:Always test your kustomization changes in a development environment before applying them to production. This helps prevent accidental misconfigurations.