# How to automate image updates with Flux, step by step

> Set up Flux image automation: scan a registry, pick tags with semver or filterTags, mark manifests with setters and push updates to a review branch.

Published: 2026-11-26
Author: k8wiz Team
URL: https://k8wiz.com/articles/flux-image-update-automation-step-by-step

With plain GitOps, every new release needs a commit that changes an image tag. Someone has to write that commit, and for patch releases it is pure busywork. Flux can write it for you. It scans a container registry, picks the newest tag that matches a rule you define, edits the manifest in Git and pushes a commit. The cluster then deploys that commit like any other, so Git history stays the record of what ran when.

This guide builds that loop from scratch on a GitHub repository. The updates go to a separate branch and arrive as pull requests, so a person still approves what reaches the cluster. You need the `flux`, `kubectl` and `git` command line tools, a GitHub personal access token in `GITHUB_TOKEN`, and a cluster you can bootstrap.

## How the pieces fit

Three objects do the work, run by two controllers that `flux bootstrap` doesn't install unless you ask for them. image-reflector-controller reconciles ImageRepository objects, which scan a registry for tags, and ImagePolicy objects, which choose the latest allowed tag. image-automation-controller reconciles ImageUpdateAutomation objects, which clone a Git repository, rewrite marked fields to the tag each policy chose, commit and push.

All three use `apiVersion: image.toolkit.fluxcd.io/v1`. If you copy examples from older blog posts, you will see `v1beta1` or `v1beta2`. Both are gone. image-reflector-controller and image-automation-controller removed `v1beta2` in their v1.2.0 releases, so a manifest with the old version fails to apply on a current Flux.

## Step 1: bootstrap with the image controllers and a write key

The image controllers are opt-in, so name them with `--components-extra`. The automation also has to push to the repository, and by default the SSH deploy key that bootstrap registers on GitHub is read-only. `--read-write-key` registers it with write access instead.

```bash
export GITHUB_TOKEN=<your-token>
export GITHUB_USER=<your-username>

flux bootstrap github \
  --components-extra=image-reflector-controller,image-automation-controller \
  --owner=$GITHUB_USER \
  --repository=fleet-infra \
  --branch=main \
  --path=clusters/my-cluster \
  --read-write-key \
  --personal
```

If the cluster was bootstrapped before with a read-only key, running bootstrap again won't fix the key. Bootstrap never overwrites the `flux-system` Secret that holds it. Delete the Secret first, then rerun the same command with both flags, and bootstrap generates a new key pair and registers it with write access.

```bash
kubectl -n flux-system delete secret flux-system
```

A write key on the repository that defines your cluster is a real grant of power. Anything that can read the `flux-system` Secret can now push to that repository, so keep RBAC on the `flux-system` namespace tight.

## Step 2: deploy an app to update

The example app is podinfo, a small web server whose images are public on GitHub Container Registry. Clone the repository and add a Deployment pinned to an older tag, so the automation has something to update.

```bash
git clone https://github.com/$GITHUB_USER/fleet-infra
cd fleet-infra

cat <<EOF > ./clusters/my-cluster/podinfo-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: podinfo
  namespace: default
spec:
  selector:
    matchLabels:
      app: podinfo
  template:
    metadata:
      labels:
        app: podinfo
    spec:
      containers:
        - name: podinfod
          image: ghcr.io/stefanprodan/podinfo:6.0.0
          ports:
            - name: http
              containerPort: 9898
              protocol: TCP
EOF

git add -A && git commit -m "Add podinfo" && git push origin main
flux reconcile kustomization flux-system --with-source
```

## Step 3: scan the registry with an ImageRepository

An ImageRepository names one image and how often to list its tags. Five minutes is fine for a demo. In production, a longer interval plus a registry webhook keeps you under registry rate limits and still reacts quickly to new pushes.

```yaml
apiVersion: image.toolkit.fluxcd.io/v1
kind: ImageRepository
metadata:
  name: podinfo
  namespace: flux-system
spec:
  image: ghcr.io/stefanprodan/podinfo
  interval: 5m
```

Save it as `clusters/my-cluster/podinfo-registry.yaml`. You can also generate the same manifest with `flux create image repository podinfo --image=ghcr.io/stefanprodan/podinfo --interval=5m --export`. For a private registry, create a `docker-registry` Secret in the same namespace and reference it with `spec.secretRef.name`.

The scan skips tags that match `spec.exclusionList`. When you leave the field out, it defaults to `^.*\.sig$`, which hides the signature tags that Cosign pushes next to each image. If you set your own list, add that pattern back, or a signature tag can end up competing with real releases.

## Step 4: choose tags with an ImagePolicy

The ImagePolicy decides which scanned tag counts as latest. For a release stream, a semver range is the safest rule. This one takes any 6.x release and never jumps to 7.0, because a major version is where breaking changes live and deserves a deliberate commit.

```yaml
apiVersion: image.toolkit.fluxcd.io/v1
kind: ImagePolicy
metadata:
  name: podinfo
  namespace: flux-system
spec:
  imageRepositoryRef:
    name: podinfo
  policy:
    semver:
      range: ">=6.0.0 <7.0.0"
```

A range like `6.0.x` limits updates to patches. Prereleases such as `6.1.0-rc.1` are left out unless the range itself has a prerelease part, for example `>=6.0.0-0`.

Not every image has version tags. A staging environment often runs builds of the main branch tagged like `main-2d3fcbd-1611906956`, with the short commit SHA and a Unix timestamp. Semver can't order those, so use `filterTags` to keep only main builds and pull out the timestamp, then sort the extracted values as numbers.

```yaml
apiVersion: image.toolkit.fluxcd.io/v1
kind: ImagePolicy
metadata:
  name: podinfo-main
  namespace: flux-system
spec:
  imageRepositoryRef:
    name: podinfo
  filterTags:
    pattern: '^main-[a-fA-F0-9]+-(?P<ts>[1-9][0-9]*)'
    extract: '$ts'
  policy:
    numerical:
      order: asc
```

The `pattern` decides which tags take part at all, and `extract` decides what the policy compares. Sorting the full tag alphabetically would order builds by commit SHA, which is random. That is the reason the timestamp sits in the tag in the first place.

Commit both files, reconcile, and check that the scan and the policy worked.

```bash
git add -A && git commit -m "Scan podinfo images" && git push origin main
flux reconcile kustomization flux-system --with-source

flux get image repository podinfo
flux get image policy podinfo
```

The repository's message reports how many tags the scan found. The policy's message has the form `Latest image tag for ghcr.io/stefanprodan/podinfo resolved to <tag>`, and that tag is what the automation will write to Git.

## Step 5: mark the manifest with a setter

The automation never guesses which line to change. It only touches fields that carry a setter comment naming a policy as `namespace:name`. Edit the Deployment's image line.

```yaml
      containers:
        - name: podinfod
          image: ghcr.io/stefanprodan/podinfo:6.0.0 # {"$imagepolicy": "flux-system:podinfo"}
```

This plain form replaces the whole image reference. When a chart splits the image into separate values, append `:name`, `:tag` or `:digest` to the policy reference so each line gets only its part.

```yaml
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: podinfo
  namespace: default
spec:
  values:
    image:
      repository: ghcr.io/stefanprodan/podinfo # {"$imagepolicy": "flux-system:podinfo:name"}
      tag: 6.0.0 # {"$imagepolicy": "flux-system:podinfo:tag"}
```

A `:digest` setter only gets a value when the ImagePolicy sets `spec.digestReflectionPolicy` to `IfNotPresent` or `Always`. The default is `Never`, which reports no digest at all.

## Step 6: push updates to a branch with ImageUpdateAutomation

The ImageUpdateAutomation ties it together. It checks out `main` from the `flux-system` GitRepository that bootstrap created, which is how it gets the write key. It looks for setters only under `spec.update.path`, and pushes its commits to `flux-image-updates` instead of `main`.

```yaml
apiVersion: image.toolkit.fluxcd.io/v1
kind: ImageUpdateAutomation
metadata:
  name: flux-system
  namespace: flux-system
spec:
  interval: 30m
  sourceRef:
    kind: GitRepository
    name: flux-system
  git:
    checkout:
      ref:
        branch: main
    commit:
      author:
        email: fluxcdbot@users.noreply.github.com
        name: fluxcdbot
      messageTemplate: |
        Update container images

        {{ .Changed.Summary }}
    push:
      branch: flux-image-updates
  update:
    path: ./clusters/my-cluster
    strategy: Setters
```

Save it as `clusters/my-cluster/image-automation.yaml`. The `flux create image update` command produces the same object with `--git-repo-ref`, `--git-repo-path`, `--checkout-branch`, `--push-branch`, `--author-name`, `--author-email` and `--commit-template`.

Pushing to its own branch changes what the automation means. The cluster still syncs from `main`, so nothing deploys until someone merges, and branch protection on `main` can stay as strict as you like. If the push branch doesn't exist, the controller creates it from the checkout branch. If it does exist, the controller overwrites it with a fresh copy of `main` plus its changes. The branch never drifts behind `main`, and an open pull request simply updates with each run.

The template's `.Changed.Summary` writes one line per change. For the plain setter above, the line looks like `ghcr.io/stefanprodan/podinfo:6.0.0 -> ghcr.io/stefanprodan/podinfo:6.x.y`, so the commit says exactly what moved.

The automation applies every ImagePolicy in its own namespace. If you run several automations side by side, give each one a `spec.policySelector` with `matchLabels`, so each picks up only its own policies.

## Step 7: open pull requests automatically

A branch that nobody looks at isn't a review process. A short GitHub Actions workflow in the same repository opens a pull request each time the automation creates the branch. Save this one, which follows the example in the Flux docs, as `.github/workflows/image-updates-pr.yaml`.

```yaml
name: Image updates PR
on:
  create:

jobs:
  pull-request:
    runs-on: ubuntu-latest
    if: |
      github.event.ref_type == 'branch' &&
      github.event.ref == 'flux-image-updates'
    permissions:
      pull-requests: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Create pull request
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_REPO: ${{ github.repository }}
        run: |
          gh pr create \
            --repo=${GITHUB_REPO} \
            --head=flux-image-updates \
            --base=main \
            --title="Automated image updates" \
            --body="Image tags updated by Flux image automation."
```

The workflow fires on branch creation only. Turn on "Automatically delete head branches" in the repository settings, so merging the pull request removes the branch and the next update creates it again, which opens the next pull request.

## Step 8: commit and watch it work

Push the setter change, the automation and the workflow together, then nudge Flux instead of waiting for intervals.

```bash
git add -A && git commit -m "Add image update automation" && git push origin main
flux reconcile kustomization flux-system --with-source
flux reconcile image update flux-system

flux get images all -n flux-system
```

Within a few seconds, a `flux-image-updates` branch with one commit by `fluxcdbot` appears on GitHub, and the workflow opens a pull request for it. Merge it, and Flux deploys the new tag on its next sync of `main`.

```bash
git pull
kubectl -n default get deployment podinfo \
  -o jsonpath='{.spec.template.spec.containers[0].image}'
```

## When something goes wrong

If no commit appears, `flux get image update flux-system` shows the automation's last error. A push rejected for lack of permission usually means the deploy key is still read-only, and step 1 covers the fix. A Ready automation that never commits usually means a setter names the wrong `namespace:name`, or the manifest sits outside `spec.update.path`.

During an incident, stop all updates with `flux suspend image update flux-system`, and resume them with `flux resume image update flux-system`. To hold back one image while the rest keep flowing, suspend its scan with `flux suspend image repository podinfo`. To roll back, narrow the semver range to the last good version and commit that. The automation then rewrites the tag to it, and the rollback is recorded in Git like everything else.
