← Recipes

阅读中文版本

Automate Image Updates with Flux

Add an ImageRepository and ImagePolicy, let Flux commit the selected tag back to Git, and keep deployments moving without manually editing tags.

~45 mingitopsfluxdeployment

Task

Automate container image tag updates in Git using Flux image automation.

When to use this

New image tags are built continuously, but someone must hand-edit the deployment tag, so releases lag behind what is actually built.

Prerequisites

  • Flux with image automation controllers
  • Write access for Flux to the Git repo

Steps

1. Create an ImageRepository pointing at the registry and image.

Expected output: Flux scans tags and metadata.

2. Create an ImagePolicy to select the newest tag by your policy.

Expected output: A deterministic tag is chosen.

3. Create an ImageUpdateAutomation that writes the selected tag back to Git.

Expected output: Git holds the desired tag and reconciles.

4. Mark manifests with the settable image marker so Flux can patch them.

flux get images all

Expected output: Updates land in the right place.

Troubleshooting

Problem

Wrong tag selected

Solution

Tighten the ImagePolicy semver or regex filter so prerelease or dated tags are excluded.

Problem

Update loop

Solution

Ensure the automation commit does not trigger another scan cycle that changes the same field.

Limitations

  • Automated tag updates can push an unwanted image if the tag policy is loose; review the filter carefully.
  • Image automation commits to Git, which may conflict with branch protection or other automation.

Context

Automate container image tag updates in Git using Flux image automation. New image tags are built continuously, but someone must hand-edit the deployment tag, so releases lag behind what is actually built.

Steps

  1. Create an ImageRepository pointing at the registry and image. Expected: Flux scans tags and metadata.
  2. Create an ImagePolicy to select the newest tag by your policy. Expected: A deterministic tag is chosen.
  3. Create an ImageUpdateAutomation that writes the selected tag back to Git. Expected: Git holds the desired tag and reconciles.
  4. Mark manifests with the settable image marker so Flux can patch them. Expected: Updates land in the right place.
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImagePolicy
metadata: { name: app }
spec:
  imageRepositoryRef: { name: app }
  policy:
    semver: { range: ">=1.0.0" }

Verify

  • Flux scans tags and metadata.
  • A deterministic tag is chosen.
  • Git holds the desired tag and reconciles.
  • Updates land in the right place.

Limits

  • Automated tag updates can push an unwanted image if the tag policy is loose; review the filter carefully.
  • Image automation commits to Git, which may conflict with branch protection or other automation.