You create a job in {product-title} by creating a job object.
To create a job:
-
Create a YAML file similar to the following:
apiVersion: batch/v1 kind: Job metadata: name: pi spec: parallelism: 1 (1) completions: 1 (2) activeDeadlineSeconds: 1800 (3) backoffLimit: 6 (4) template: (5) metadata: name: pi spec: containers: - name: pi image: perl command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] restartPolicy: OnFailure (6)
-
Optionally, specify how many pod replicas a job should run in parallel; defaults to
1
.-
For non-parallel jobs, leave unset. When unset, defaults to
1
.
-
-
Optionally, specify how many successful pod completions are needed to mark a job completed.
-
For non-parallel jobs, leave unset. When unset, defaults to
1
. -
For parallel jobs with a fixed completion count, specify the number of completions.
-
For parallel jobs with a work queue, leave unset. When unset defaults to the
parallelism
value.
-
-
Optionally, specify the maximum duration the job can run.
-
Optionally, specify the number of retries for a job. This field defaults to six.
-
Specify the template for the pod the controller creates.
-
Specify the restart policy of the pod:
-
Never
. Do not restart the job. -
OnFailure
. Restart the job only if it fails. -
Always
. Always restart the job.
-
-
For details on how {product-title} uses restart policy with failed containers, see the Example States in the Kubernetes documentation.
-
Create the job:
$ oc create -f <file-name>.yaml
Note
|
You can also create and launch a job from a single command using $ oc run pi --image=perl --replicas=1 --restart=OnFailure \ --command -- perl -Mbignum=bpi -wle 'print bpi(2000)' |