Add automatic image updates

This commit is contained in:
Tyler Perkins 2024-11-16 13:46:41 -05:00
parent b4047abaef
commit 627c8e58cf
Signed by: tyler
GPG Key ID: 03B27509E17EFDC8
4 changed files with 90 additions and 1 deletions

View File

@ -0,0 +1,25 @@
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImageUpdateAutomation
metadata:
name: flux-system
namespace: flux-system
spec:
git:
checkout:
ref:
branch: main
commit:
author:
email: fluxcdbot@users.noreply.github.com
name: fluxcdbot
messageTemplate: '{{range .Changed.Changes}}{{print .OldValue}} -> {{println
.NewValue}}{{end}}'
push:
branch: main
interval: 15m0s
sourceRef:
kind: GitRepository
name: flux-system
update:
path: ./cluster
strategy: Setters

View File

@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: documentation-site
image: git.clortox.com/infrastructure/gluttony-cluster/documentation:0.0.1
image: git.clortox.com/infrastructure/gluttony-cluster/documentation:0.0.1 # {"$imagepolicy": "flux-system:gluttony-cluster-documentation"}
ports:
- name: http
containerPort: 80

View File

@ -0,0 +1,63 @@
# 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`

View File

@ -41,6 +41,7 @@ nav:
- NFS: technical/nfs-storage.md
- Seal-a-secret: technical/seal-a-secret.md
- Networking: technical/inter-pod-networking.md
- Automatic Image Updates: technical/auto-image-updates.md
theme:
name: material