Is it possible to rerun kubernetes job?
Solution 1:
You can simulate a rerun by replacing the job with itself:
kubectl get job "your-job" -o json | kubectl replace --force -f -
If you get errors due to auto-generated labels or selectors, you can delete or edit them with jq:
kubectl get job "your-job" -o json | jq 'del(.spec.selector)' | jq 'del(.spec.template.metadata.labels)' | kubectl replace --force -f -
Solution 2:
No. There is definitely no way to rerun a kubernetes job. You need to delete it first.
Solution 3:
You can also avoid the error you mentioned by specifying
generateName: dbload
instead of simply name
In that case, each job you submit with this yaml file will have a unique name that will look something like dbloada1b2c
. Then you can decide whether you need to delete the old jobs, but you won't have to do it.
Here is a working yaml example:
apiVersion: batch/v1
kind: Job
metadata:
generateName: netutils-
spec:
parallelism: 1
template:
spec:
containers:
- image: amouat/network-utils
name: netutil
restartPolicy: Never
This is the output from kubectl get job
after two kubectl create -f example.yaml
commands:
NAME COMPLETIONS DURATION AGE
netutils-5bs2s 0/1 14s 14s
netutils-dsvfk 0/1 10s 10s