Skip to content

Latest commit

 

History

History
68 lines (59 loc) · 2.13 KB

nodes-nodes-jobs-creating.adoc

File metadata and controls

68 lines (59 loc) · 2.13 KB

Creating jobs

You create a job in {product-title} by creating a job object.

Procedure

To create a job:

  1. 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)
    1. 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.

    2. 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.

    3. Optionally, specify the maximum duration the job can run.

    4. Optionally, specify the number of retries for a job. This field defaults to six.

    5. Specify the template for the pod the controller creates.

    6. 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.

  1. 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. The following command creates and launches the same job as specified in the previous example:

$ oc run pi --image=perl --replicas=1  --restart=OnFailure \
    --command -- perl -Mbignum=bpi -wle 'print bpi(2000)'