Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

05 — jobGroups (Job + CronJob)

Two jobGroups in one release:

  • migrations — kind: Job, runs as a PreSync hook on every Argo CD sync. Tasks-mode: two ordered initContainers (01-structure then 02-seed) inside one Job.
  • nightly — kind: CronJob with two scheduled jobs sharing image and env: cleanup at 02:00 UTC and report at 06:00 UTC.

What this shows

  • Group-level config (image, envSecrets, hooks) cascades into every job in jobs:. Per-job fields override.
  • Tasks mode: a job whose work is split across multiple ordered initContainers, then a tiny “completed” container marks the Job successful. Useful for migration → seed pipelines where step ordering matters. Kubernetes runs initContainers sequentially in their declared order, and the chart emits the tasks map sorted alphabetically — so when ordering matters, prefix task names with 01-, 02-, 03- etc. to make the run order explicit. (See ADR 014.)
  • Single-container mode (command / args directly on the job) for the CronJob members.
  • Hash-suffixed Job names (<release>-migrations-schema-<sha8>) — the Job re-runs only when its rendered spec changes (image bump, env change, command edit). Argo CD on a 1-minute sync interval is harmless. (ADR 012)
  • Argo CD hook annotations on the migrations group → Argo CD treats those Jobs as PreSync hooks; the user-visible workloads continue applying once the hook completes.
  • CronJob fields (schedule, timeZone, concurrencyPolicy, history limits) live per job — different schedules per job in the same group.

Delta from 01-minimal

AddedWhat
jobGroups.migrationsPre-sync schema migration via tasks-mode initContainers.
jobGroups.nightlyTwo CronJobs sharing image/env, different schedules.
Argo CD hooksMigrations group runs as PreSync with syncWave: -2.
External Secret referencedb-credentials Secret carries DB_PASSWORD for migrations.

(There is no Deployment in this example — purely batch workloads.)

Files

FilePurpose
values.yamlChart values.
argocd/application.yamlArgo CD Application, single source.
argocd/application-multisource.yamlArgo CD Application with spec.sources[].
flux/ocirepository.yamlFlux OCIRepository.
flux/helmrelease.yamlFlux HelmRelease.
helm/install.shPlain helm upgrade --install.

Try it

# Pre-create the credentials Secret
kubectl create namespace batch
kubectl create secret generic db-credentials \
  --from-literal=DB_PASSWORD='changeme' \
  -n batch

bash helm/install.sh