Create jobs
Create a job to run a one-time task, configuring parallelism, completion count, time limits, retry policies, and automatic cleanup behavior.
You create a job in OpenShift Container Platform by creating a job object.
|
|
You can also create and launch a job from a single command using
|
-
Create a YAML file similar to the following:
apiVersion: batch/v1 kind: Job metadata: name: pi spec: parallelism: 1 completions: 1 activeDeadlineSeconds: 1800 backoffLimit: 6 ttlSecondsAfterFinished: 100 template: metadata: name: pi spec: containers: - name: pi image: perl command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] restartPolicy: OnFailure #...where:
spec.parallelism-
Specifies how many pod replicas a job should run in parallel; defaults to
1. For non-parallel jobs, leave unset. When unset, defaults to1. This value is optional. spec.completions-
Specifies 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 theparallelismvalue. This value is optional. spec.activeDeadlineSeconds-
Specifies the maximum duration the job can run. This value is optional.
spec.backoffLimit-
Specifies the number of retries for a job. This field defaults to six. This value is optional.
spec.ttlSecondsAfterFinished-
Specifies the period of time in seconds after which the job should be automatically deleted upon completion. If set to '0', the job is immediately deleted after completion. If this field is not included, the job is not automatically deleted. This value is optional.
spec.template-
Specifies the template for the pod the controller creates.
spec.template.spec.restartPolicy-
Specifies the restart policy of the pod:
Never(Do not restart the job),OnFailure(Restart the job only if it fails), orAlways(Always restart the job). For details on how OpenShift Container Platform uses restart policy with failed containers, see the Example States in the Kubernetes documentation.
-
Create the job:
$ oc create -f <file-name>.yaml