Skip to main content
In this tutorial, we’ll use Flux’s ImageRepository Custom Resource Definition (CRD) to connect to a Docker Hub repository and fetch image tags automatically. Flux provides three subcommands under flux create image: policy, repository, and update. We’ll focus on the repository subcommand to set up continuous image discovery and metadata polling.

Overview of Flux Image Commands

1. Create an ImageRepository

First, verify the available options:
Define an ImageRepository manifest that points to your Docker Hub image and polls it at a regular interval:
Make sure your Git repository includes the flux-system namespace and the Flux controllers are installed before applying this manifest.
You can export this manifest directly with the Flux CLI:
Commit and push the YAML to your Git repository, then trigger reconciliation:
Verify the repository registration and initial scan:
At this point, Flux has detected the 7.8.0 tag in your Docker Hub repository.

2. Update the Application and Push a New Tag

2.1 Modify the PHP Source

Open bb-app-source/src/index.php (and level2.php) and update the styling as well as the app version to 7.8.1:
Be sure to update all source files (e.g., level2.php) to keep version consistency.

2.2 Build and Push the Docker Image

Ensure your Dockerfile includes the necessary PHP extensions and copies your application files:
Build and tag the new image version 7.8.1:
Push the updated image to Docker Hub:
After pushing, verify on Docker Hub that the 7.8.1 tag is available.

3. Flux Scans the New Tag

Trigger an immediate reconciliation for the ImageRepository:
Re-run the flux get image command to confirm that two tags are now detected:
Alternatively, inspect the resource via kubectl:
Even though two tags exist, your Deployment is still running the old version:

Next Steps

Automate tag selection and deployment by creating a Flux ImagePolicy that matches your versioning scheme (e.g., semver or regex). This will ensure your Kubernetes workload always uses the latest approved image.

Watch Video

Practice Lab