Skip to content

Commit 80a53a9

Browse files
committed
Add Kubernetes CronJob example
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent c5d300b commit 80a53a9

2 files changed

Lines changed: 115 additions & 2 deletions

File tree

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ on upstream chart repositories.
4343
tag) is reported as a distinct outcome and exit code, so audit pipelines
4444
can differentiate "out of date" from "mutated tags".
4545
- **Ambient auth** — credentials come from `~/.docker/config.json` and the
46-
configured credential helpers (ACRm ECR, GAR, etc.). One `docker login` covers
46+
configured credential helpers (ACR, ECR, GAR, etc.). One `docker login` covers
4747
source and destination.
4848
- **Structured output**`text`, `yaml` and `json` for downstream
4949
tooling, plus a verbose mode that streams every blob and manifest digest
@@ -173,11 +173,20 @@ The `ghcr.io/fluxcd/flux-mirror` image can be used in container-based CI pipelin
173173

174174
```shell
175175
docker run --rm \
176+
-e DOCKER_CONFIG=/.docker \
176177
-v "$PWD/flux-mirror.yaml:/config.yaml:ro" \
177-
-v "$HOME/.docker/config.json:/home/nonroot/.docker/config.json:ro" \
178+
-v "$HOME/.docker/config.json:/.docker/config.json:ro" \
178179
ghcr.io/fluxcd/flux-mirror:latest sync -c /config.yaml --no-progress
179180
```
180181

182+
### Kubernetes
183+
184+
To run `flux-mirror sync` from inside a cluster on a schedule, see the
185+
[`examples/cronjob.yaml`](examples/cronjob.yaml) manifest. It bundles a
186+
`ConfigMap` with the sync config and a `CronJob` that mounts the
187+
destination registry credentials from a `Secret` created via
188+
`flux create secret oci`.
189+
181190
## Commands
182191

183192
| Command | Description |

examples/cronjob.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Create the destination registry pull secret with:
2+
# flux -n flux-system create secret oci ghcr-auth \
3+
# --url=ghcr.io \
4+
# --username=<github-user> \
5+
# --password=<github-token-with-write:packages>
6+
#
7+
# Edit the ConfigMap below to set your own source and destination registries,
8+
# then apply the manifest with:
9+
# kubectl apply -f cronjob.yaml
10+
#
11+
# To trigger an out-of-band run instead of waiting for the schedule:
12+
# kubectl -n flux-system create job --from=cronjob/flux-mirror-podinfo flux-mirror-now
13+
---
14+
apiVersion: v1
15+
kind: ConfigMap
16+
metadata:
17+
name: flux-mirror-config
18+
namespace: flux-system
19+
data:
20+
mirror.yaml: |
21+
apiVersion: mirror.fluxcd.io/v1alpha1
22+
kind: Config
23+
charts:
24+
- name: podinfo
25+
source: https://stefanprodan.github.io/podinfo
26+
destination: oci://ghcr.io/my-org/charts
27+
version: "*"
28+
limit: 1
29+
artifacts:
30+
- source: ghcr.io/stefanprodan/podinfo
31+
destination: ghcr.io/my-org/podinfo
32+
selector:
33+
semver: "*"
34+
limit: 1
35+
includeReferrers: true
36+
---
37+
apiVersion: batch/v1
38+
kind: CronJob
39+
metadata:
40+
name: flux-mirror-podinfo
41+
namespace: flux-system
42+
spec:
43+
schedule: "0 */6 * * *"
44+
concurrencyPolicy: Forbid
45+
successfulJobsHistoryLimit: 1
46+
failedJobsHistoryLimit: 2
47+
jobTemplate:
48+
spec:
49+
backoffLimit: 2
50+
template:
51+
spec:
52+
restartPolicy: OnFailure
53+
securityContext:
54+
runAsNonRoot: true
55+
runAsUser: 65534
56+
runAsGroup: 65534
57+
fsGroup: 65534
58+
seccompProfile:
59+
type: RuntimeDefault
60+
containers:
61+
- name: flux-mirror
62+
image: ghcr.io/fluxcd/flux-mirror:latest
63+
imagePullPolicy: IfNotPresent
64+
args:
65+
- sync
66+
- --config=/config/flux/mirror.yaml
67+
- --no-progress
68+
- --output=text
69+
env:
70+
- name: DOCKER_CONFIG
71+
value: /config/docker
72+
securityContext:
73+
allowPrivilegeEscalation: false
74+
readOnlyRootFilesystem: true
75+
capabilities:
76+
drop: ["ALL"]
77+
resources:
78+
requests:
79+
cpu: 100m
80+
memory: 64Mi
81+
limits:
82+
cpu: 2000m
83+
memory: 256Mi
84+
volumeMounts:
85+
- name: config
86+
mountPath: /config/flux
87+
readOnly: true
88+
- name: docker-config
89+
mountPath: /config/docker
90+
readOnly: true
91+
- name: tmp
92+
mountPath: /tmp
93+
volumes:
94+
- name: config
95+
configMap:
96+
name: flux-mirror-config
97+
- name: docker-config
98+
secret:
99+
secretName: ghcr-auth
100+
items:
101+
- key: .dockerconfigjson
102+
path: config.json
103+
- name: tmp
104+
emptyDir: {}

0 commit comments

Comments
 (0)