Add automatic image updates
This commit is contained in:
parent
b4047abaef
commit
627c8e58cf
25
cluster/flux-system-automation.yaml
Normal file
25
cluster/flux-system-automation.yaml
Normal 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
|
@ -14,7 +14,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: documentation-site
|
- 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:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
containerPort: 80
|
containerPort: 80
|
||||||
|
63
docs/technical/auto-image-updates.md
Normal file
63
docs/technical/auto-image-updates.md
Normal 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`
|
@ -41,6 +41,7 @@ nav:
|
|||||||
- NFS: technical/nfs-storage.md
|
- NFS: technical/nfs-storage.md
|
||||||
- Seal-a-secret: technical/seal-a-secret.md
|
- Seal-a-secret: technical/seal-a-secret.md
|
||||||
- Networking: technical/inter-pod-networking.md
|
- Networking: technical/inter-pod-networking.md
|
||||||
|
- Automatic Image Updates: technical/auto-image-updates.md
|
||||||
|
|
||||||
theme:
|
theme:
|
||||||
name: material
|
name: material
|
||||||
|
Loading…
Reference in New Issue
Block a user