64 lines
1.8 KiB
Markdown
64 lines
1.8 KiB
Markdown
|
# Automatic Image Updates
|
||
|
|
||
|
If you want flux to automatically update container images, this is how.
|
||
|
Based on [this](https://fluxcd.io/flux/guides/image-update/) documentation.
|
||
|
|
||
|
|
||
|
## Make the deployment
|
||
|
|
||
|
Start by making a normal deployment how you would normally. Just note not to use `latest` as your tag.
|
||
|
(You shouldn't be anyways).
|
||
|
|
||
|
## Add an image scanner
|
||
|
|
||
|
Create an image scanner to go pull new image versions.
|
||
|
|
||
|
```bash
|
||
|
flux create image repository MYNAME \
|
||
|
--image=git.clortox.com/infrastructure/my-cool-image \
|
||
|
--internal=5m \
|
||
|
--export > MYNAME-registry.yaml
|
||
|
```
|
||
|
|
||
|
Next make the `ImagePolicy` to choose what semver to filter for.
|
||
|
|
||
|
```bash
|
||
|
flux create image policy MYNAME \
|
||
|
--image-ref=MYNAME \
|
||
|
--select-semver=0.0.x \
|
||
|
--export > MYNAME-policy.yaml
|
||
|
```
|
||
|
|
||
|
## Configure Image Updates
|
||
|
|
||
|
At this point flux can scan peridoically and see that new images are released.
|
||
|
Now lets automatically pull them down, and update the git repo.
|
||
|
|
||
|
First, we have to tell flux where it should apply updates in our manifests.
|
||
|
To do that, add the following comment to the end of the line in your deployment
|
||
|
|
||
|
```yaml
|
||
|
image: git.clortox.com/infrastructure/gluttony-cluster/documentation:0.0.1 # {"$imagepolicy": "flux-system:MYNAME"}
|
||
|
```
|
||
|
|
||
|
The syntax here is `NAMESPACE:IMAGE_POLICY_NAME`.
|
||
|
|
||
|
After this, lets make the updater for the entire system.
|
||
|
|
||
|
```bash
|
||
|
flux create image update flux-system \
|
||
|
--interval=15m \
|
||
|
--git-repo-ref=flux-system \
|
||
|
--git-repo-path="./cluster" \
|
||
|
--checkout-branch=main \
|
||
|
--push-branch=main \
|
||
|
--author-name=fluxcdbot \
|
||
|
--author-email=fluxcdbot@users.noreply.github.com \
|
||
|
--commit-template="{{range .Changed.Changes}}{{print .OldValue}} -> {{println .NewValue}}{{end}}" \
|
||
|
--export > ./flux-system-automation.yaml
|
||
|
```
|
||
|
|
||
|
> [!NOTE]
|
||
|
>
|
||
|
> `flux-system` is the default source name. Check it with `flux get source git`
|