Init Container and Jobs
Configure chart.initContainer, wait-for-job with RBAC, chart.job, and the root job helper in ohMyHelm, including known template limitations and workarounds.
Init Container and Jobs
For initialization tasks that must run before the actual application starts (such as database migrations or waiting on a setup job), ohMyHelm provides chart.initContainer, chart.job, and the standalone root job helper.
Init Container (chart.initContainer)
In Chart mode, ohMyHelm supports a single init container (chart.initContainer, singular) with the fixed container name <chartName>-init.
Supported Fields and Limitations
- Supported:
enabled,image,imageConfig.pullPolicy,command,args,staticEnv,env,extraEnv,envFrom. - Not supported:
volumeMounts,resources,securityContext, and multiple init containers. If you need multiple init containers or volume mounts in an init container, render the complete workload manifest via themanifestshelper.
Default Image: Wait-for-Job
By default, chart.initContainer.image is preconfigured to registry.gitlab.com/ayedocloudsolutions/ohmyhelm-job-helper:1.0.0 with args: ["job", "yourjobnamehere"]. This helper queries the Kubernetes API and blocks startup of the main container until the specified batch/v1 Job has succeeded.
Chart Job (chart.job) vs. Root Helper (job)
ohMyHelm includes two Job templates:
chart.job(omh-chart-job.yaml): Automatically falls back tochart.container.imagewhen no separatechart.job.imageis specified, and inheritschart.imagePullSecrets.- Root-level
job(omh-helper-job.yaml): Standalone helper without Chart dependency, with its ownimageandimagePullSecrets.
Practical Example 1: Migration Job via Root Helper job + Wait-for-Job Init Container
This combination works reliably in the current chart release, including command/args and least-privilege RBAC:
# 1. Migration job via the root `job` helper (renders command/args properly as YAML lists)
job:
enabled: true
name: "acme-db-migrate"
image: registry.acme.corp/backend:2.0.0
imageConfig:
pullPolicy: IfNotPresent
command:
- "/app/migrate"
args:
- "up"
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: acme-db-credentials
key: url
restartPolicy: Never
backoffLimit: 3
activeDeadlineSeconds: 300
removejob:
enabled: true
ttlSecondsAfterFinished: 120
# 2. Application waits in its init container for `acme-db-migrate` to succeed
chart:
enabled: true
fullnameOverride: "acme-backend"
serviceAccount:
create: true
rbac:
enabled: true
roleRules:
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["get", "list", "watch"]
initContainer:
enabled: true
image: registry.gitlab.com/ayedocloudsolutions/ohmyhelm-job-helper:1.0.0
args:
- "job"
- "acme-db-migrate"
container:
image: registry.acme.corp/backend:2.0.0
ports:
- name: http
containerPort: 8080
resources:
requests:
cpu: 100m
memory: 128Mi
Practical Example 2: chart.job with a Dedicated Migration Image (No command/args Override)
If your image already defines the migration command as its default ENTRYPOINT, you can use chart.job directly and leave command/args empty:
chart:
enabled: true
fullnameOverride: "acme-backend"
job:
enabled: true
name: "acme-db-migrate"
image: registry.acme.corp/backend-migrator:2.0.0
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
env:
- name: DATABASE_HOST
value: acme-postgres
extraVolumeMounts:
- name: ca-cert
mountPath: /etc/ssl/certs/acme-ca.crt
subPath: acme-ca.crt
readOnly: true
extraVolumes:
- name: ca-cert
configMap:
name: acme-ca-bundle
restartPolicy: Never
backoffLimit: 3
activeDeadlineSeconds: 600
removejob:
enabled: true
ttlSecondsAfterFinished: 300
container:
image: registry.acme.corp/backend:2.0.0
ports:
- name: http
containerPort: 8080
Recurring Tasks (CronJob)
ohMyHelm does not include a built-in CronJob template. Define recurring batch tasks directly via the manifests helper using apiVersion: batch/v1 and kind: CronJob.