• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. API Reference 2.0
  4. Kubernetes API
  5. Job
  6. Creating a Job

Creating a Job

Function

This API is used to create a Job resource object.

URI

POST /apis/batch/v1/namespaces/{namespace}/jobs

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Mandatory

Description

namespace

Yes

Object name and auth scope, such as for teams and projects.

pretty

No

If 'true', then the output is pretty printed.

Request

Request parameters:

Table 2 Request parameter

Parameter

Mandatory

Type

Description

apiVersion

Yes

String

APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values.

kind

Yes

String

Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated.

metadata

Yes

Table 11

Standard list metadata.

spec

Yes

Table 4

Spec defines the desired identities of pods in this set.

status

No

Table 3

Status is the current status of Pods in this Job. This data may be out of date by some window of time.

Table 3 Data structure of the status field

Parameter

Mandatory

Type

Description

active

No

Integer

The number of actively running pods.

completionTime

No

Time

Replicas is the number of actual replicas.

conditions

No

Table 8

The latest available observations of an object's current state. More info:

failed

No

Integer

The number of pods which reached phase Failed.

startTime

No

Time

Represents time when the job was acknowledged by the job controller. It is not guaranteed to be set in happens-before order across separate operations. It is represented in RFC3339 form and is in UTC.

succeeded

No

Integer

The number of pods which reached phase Succeeded.

Table 4 Data structure of the spec field

Parameter

Mandatory

Type

Description

activeDeadlineSeconds

No

Integer

Specifies the duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer

backoffLimit

No

Integer(int32)

Specifies the number of retries before marking this job failed. Defaults to 6.

completions

No

Integer

Specifies the desired number of successfully finished pods the job should be run with. Setting to nil means that the success of any pod signals the success of all pods, and allows parallelism to have any positive value. Setting to 1 means that parallelism is limited to 1 and the success of that pod signals the success of the job.

manualSelector

No

Boolean

manualSelector controls generation of pod labels and pod selectors. Leave manualSelector unset unless you are certain what you are doing. When false or unset, the system pick labels unique to this job and appends those labels to the pod template. When true, the user is responsible for picking unique labels and specifying the selector. Failure to pick a unique label may cause this and other jobs to not function correctly. However, You may see manualSelector=true in jobs that were created with the old extensions/v1beta1 API.

parallelism

No

Integer

Specifies the maximum desired number of pods the job should run at any given time. The actual number of pods running in steady state will be less than this number when ((.spec.completions - .status.successful) < .spec.parallelism), i.e. when the work left to do is less than max parallelism.

selector

Yes

Table 5

Selector is a label query over pods that should match the replica count. If empty, defaulted to labels on the pod template.

template

Yes

Table 7

Template is the object that describes the pod that will be created if insufficient replicas are detected. Each pod stamped out by the Job will fulfill this Template, but have a unique identity from the rest of the Job.

Table 5 Data structure of the selector field

Parameter

Mandatory

Type

Description

matchExpressions

No

Table 6

matchExpressions is a list of label selector requirements. The requirements are ANDed.

matchLabels

No

Object

MatchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed.

Table 6 Data structure of the matchExpressions field

Parameter

Mandatory

Type

Description

key

No

String

key is the label key that the selector applies to.

operator

No

String

operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist.

values

No

String

values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch.

Table 7 Data structure of the PodTemplateSpec field

Parameter

Mandatory

Type

Description

metadata

Yes

Table 11

Standard object's metadata.

spec

Yes

Table 23

Specification of the desired behavior of the pod.

Table 8 Data structure of the JobCondition field

Parameter

Mandatory

Type

Description

lastProbeTime

No

Time

Last time the condition was checked.

lastTransitionTime

No

Time

Last time the condition transit from one status to another.

message

No

String

Human readable message indicating details about last transition

reason

No

String

(brief) reason for the condition's last transition.

status

No

String

Status of the condition, one of True, False, Unknown.

type

No

String

Type of job condition, Complete or Failed.

Example request:

{
    "apiVersion": "batch/v1",
    "kind": "Job",
    "metadata": {
        "labels": {
            "name": "job-test"
        },
        "name": "job-test"
    },
    "spec": {
        "template": {
            "metadata": {
                "labels": {
                    "name": "job-test"
                },
                "name": "job-test"
            },
            "spec": {
                "containers": [
                    {
                        "image": "172.16.5.235:20202/test/nginx",
                        "name": "job-test"
                    }
                ],
                "imagePullSecrets": [{
                    "name": "default-secret"
                }],
                "restartPolicy": "Never"
            }
        }
    }
}

Response

Response parameters:

For the description about response parameters, see Table 2

Example response:

{
    "kind": "Job",
    "apiVersion": "batch/v1",
    "metadata": {
        "name": "job-test",
        "namespace": "default",
        "selfLink": "/apis/batch/v1/namespaces/default/jobs/job-test",
        "uid": "45444e9b-fc20-11e7-9c3c-fa163eb8ad1a",
        "resourceVersion": "486000",
        "creationTimestamp": "2018-01-18T07:21:58Z",
        "labels": {
            "name": "job-test"
        },
        "enable": true
    },
    "spec": {
        "parallelism": 1,
        "completions": 1,
        "selector": {
            "matchLabels": {
                "controller-uid": "45444e9b-fc20-11e7-9c3c-fa163eb8ad1a"
            }
        },
        "template": {
            "metadata": {
                "name": "job-test",
                "creationTimestamp": null,
                "labels": {
                    "controller-uid": "45444e9b-fc20-11e7-9c3c-fa163eb8ad1a",
                    "job-name": "job-test",
                    "name": "job-test"
                },
                "enable": true
            },
            "spec": {
                "containers": [
                    {
                        "name": "job-test",
                        "image": "172.16.5.235:20202/test/nginx",
                        "resources": {},
                        "terminationMessagePath": "/dev/termination-log",
                        "terminationMessagePolicy": "File",
                        "imagePullPolicy": "Always"
                    }
                ],
                "restartPolicy": "Never",
                "terminationGracePeriodSeconds": 30,
                "dnsPolicy": "ClusterFirst",
                "securityContext": {},
                "imagePullSecrets": [
                    {
                        "name": "default-secret"
                    }
                ],
                "schedulerName": "default-scheduler"
            }
        }
    },
    "status": {}
}

Status Code

Table 9 describes the status code of this API.

Table 9 Status code

Status Code

Description

201

The request has been fulfilled, resulting in the creation of a new resource.

For the description about status codes, see Status Codes.