Skip to main content
In the previous lesson, we used the ImageRepository CRD to retrieve metadata for all available image tags. Now, we’ll introduce the ImagePolicy CRD to automatically select the latest tag based on semantic versioning. By the end of this guide, you’ll know how to configure, apply, and verify an ImagePolicy in your Flux-enabled Kubernetes cluster.

1. Create an ImagePolicy

First, open your Flux cluster directory in VS Code:
Generate a new ImagePolicy manifest that references the existing ImageRepository (8-demo-image-repo-bb-app) and selects patch releases in the 7.8.x range:
This command outputs a YAML similar to:
Key fields:
  • imageRepositoryRef.name: links to the ImageRepository you created earlier.
  • policy.semver.range: 7.8.x instructs Flux to pick the highest available patch within the 7.8 series.
Semantic version ranges follow npm semver syntax; here 7.8.x matches 7.8.0, 7.8.1, etc.

2. Other Policy Selectors

Flux supports multiple policy strategies for filtering image tags: Example: a policy for release candidates (-rc):
Or a policy that always selects the most recent tag:
For more examples, see the Flux Image Policy documentation.

3. Apply and Verify the ImagePolicy

  1. Commit and push 8-demo-image-policy-bb-app.yaml to your Git repository.
  2. Run Flux CLI to view all image resources:
    Expected output:
  3. For a detailed policy status, inspect the resource in Kubernetes:

4. Deployment Remains on the Previous Version

Even though the ImagePolicy has selected 7.8.1, your running Deployment is still on 7.8.0:
An ImagePolicy alone does not update running workloads. To automate commits of updated tags back into Git, you’ll need the ImageUpdateAutomation controller, which we’ll cover next.

Thank you for following this lesson!

Watch Video