I am trying to make a Kubernetes deployment script using helm. I created following 2 jobs (skipped the container template since I guess it does not matter)
templates/jobs/migrate.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-migrate
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": post-install
"helm.sh/hook-weight": "10"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
...
templates/jobs/seed.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-seed
namespace: {{ .Release.Namespace }}
spec:
...
First job is updating the database structure.
Second job will reset the database contents and fill it with example data.
Since I did not add post-install
hook to the seed job I was expecting that job to not run automatically but only when I manually ask it to run.
But it not only ran automatically, it tried to run before migrate.
How can I define a job that I have to manually trigger for it to run?
In vanilla kubernetes jobs run only when I explicitly execute their files usingkubectl apply -f job/seed-database.yaml
How can I do the same using helm?
Replying to your last comment and thanks to @HubertNNN for his idea:
Can I run a suspended job multiple times? From documentation it seems like a one time job that cannot be rerun like normal jobs
It's normal job, you just editing yaml file with the .spec.suspend: true
and it's startTime
:
apiVersion: batch/v1
kind: Job
metadata:
name: myjob
spec:
suspend: true
parallelism: 1
completions: 5
template:
spec:
...
If all Jobs were created in the suspended state and placed in a pending queue, I can achieve priority-based Job scheduling by resuming Jobs in the right order.
More information is here