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:ImagePolicy manifest that references the existing ImageRepository (8-demo-image-repo-bb-app) and selects patch releases in the 7.8.x range:
imageRepositoryRef.name: links to theImageRepositoryyou created earlier.policy.semver.range:7.8.xinstructs 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:| Selector | Description | Example Range |
|---|---|---|
semver | Semantic version matching | ^1.2.0 |
filterTags | Regex-based tag filtering | '.*-rc.*' |
(no policy) | Always pick the latest available tag | — |
-rc):
3. Apply and Verify the ImagePolicy
-
Commit and push
8-demo-image-policy-bb-app.yamlto your Git repository. -
Run Flux CLI to view all image resources:
Expected output:
-
For a detailed policy status, inspect the resource in Kubernetes:
4. Deployment Remains on the Previous Version
Even though theImagePolicy 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.