images

Modify the name, tags and/or digest for images.

Images modify the name, tags and/or digest for images without creating patches.

One can change the image in the following ways (Refer the following example to know exactly how this is done):

  • postgres:8 to my-registry/my-postgres:v1,
  • nginx tag 1.7.9 to 1.8.0,
  • image name my-demo-app to my-app,
  • alpine’s tag 3.7 to a digest value

It is possible to set image tags for container images through the kustomization.yaml using the images field. When images are specified, Apply will override the images whose image name matches name with a new tag.

FieldDescriptionExample FieldExample Result
nameMatch images with this image namename: nginx
newTagOverride the image tag or digest for images whose image name matches namenewTag: newnginx:old -> nginx:new
newNameOverride the image name for images whose image name matches namenewName: nginx-specialnginx:old -> nginx-special:old

Example

File Input

  1. # deployment.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: the-deployment
  6. spec:
  7. template:
  8. spec:
  9. containers:
  10. - name: mypostgresdb
  11. image: postgres:8
  12. - name: nginxapp
  13. image: nginx:1.7.9
  14. - name: myapp
  15. image: my-demo-app:latest
  16. - name: alpine-app
  17. image: alpine:3.7
  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. images:
  5. - name: postgres
  6. newName: my-registry/my-postgres
  7. newTag: v1
  8. - name: nginx
  9. newTag: 1.8.0
  10. - name: my-demo-app
  11. newName: my-app
  12. - name: alpine
  13. digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
  14. resources:
  15. - deployment.yaml

Build Output

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: the-deployment
  5. spec:
  6. template:
  7. spec:
  8. containers:
  9. - image: my-registry/my-postgres:v1
  10. name: mypostgresdb
  11. - image: nginx:1.8.0
  12. name: nginxapp
  13. - image: my-app:latest
  14. name: myapp
  15. - image: alpine@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
  16. name: alpine-app

Setting a Name

The name for an image may be set by specifying newName and the name of the old container image.

  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. images:
  5. - name: mycontainerregistry/myimage
  6. newName: differentregistry/myimage

Setting a Tag

The tag for an image may be set by specifying newTag and the name of the container image.

  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. images:
  5. - name: mycontainerregistry/myimage
  6. newTag: v1

Setting a Digest

The digest for an image may be set by specifying digest and the name of the container image.

  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. images:
  5. - name: alpine
  6. digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3

Setting a Tag from the latest commit SHA

A common CI/CD pattern is to tag container images with the git commit SHA of source code. e.g. if the image name is foo and an image was built for the source code at commit 1bb359ccce344ca5d263cd257958ea035c978fd3 then the container image would be foo:1bb359ccce344ca5d263cd257958ea035c978fd3.

A simple way to push an image that was just built without manually updating the image tags is to download the kustomize standalone tool and run kustomize edit set image command to update the tags for you.

Example: Set the latest git commit SHA as the image tag for foo images.

  1. kustomize edit set image foo:$(git log -n 1 --pretty=format:"%H")
  2. kubectl apply -f .

Setting a Tag from an Environment Variable

It is also possible to set a Tag from an environment variable using the same technique for setting from a commit SHA.

Example: Set the tag for the foo image to the value in the environment variable FOO_IMAGE_TAG.

  1. kustomize edit set image foo:$FOO_IMAGE_TAG
  2. kubectl apply -f .

Committing Image Tag Updates

The kustomization.yaml changes may be committed back to git so that they can be audited. When committing the image tag updates that have already been pushed by a CI/CD system, be careful not to trigger new builds + deployments for these changes.