文档首页 > > API参考> Kubernetes API> Job> 创建Job

创建Job

分享
更新时间:2020/05/26 GMT+08:00

功能介绍

This API is used to create a Job resource object.

URI

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

表1描述该API的参数。

表1 参数解释

参数

是否必选

描述

namespace

Yes

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

pretty

No

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

请求消息

请求参数:

请求参数如表2所示。

表2 请求参数

参数

是否必选

参数类型

描述

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

metadata object

Standard list metadata.

spec

Yes

spec object

Spec defines the desired identities of pods in this set.

status

No

status object

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

表3 status字段数据结构说明

参数

是否必选

参数类型

描述

active

No

Integer

The number of actively running pods.

completionTime

No

String

Replicas is the number of actual replicas.

conditions

No

JobCondition object

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

String

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.

表4 spec字段数据结构说明

参数

是否必选

参数类型

描述

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

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

selector object

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

template

Yes

template object

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

表5 selector字段数据结构说明

参数

是否必选

参数类型

描述

matchExpressions

No

matchExpressions object

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.

表6 matchExpressions字段数据结构说明

参数

是否必选

参数类型

描述

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.

表7 PodTemplateSpec字段数据结构说明

参数

是否必选

参数类型

描述

metadata

Yes

metadata object

Standard object's metadata.

spec

Yes

spec object

Specification of the desired behavior of the pod.

表8 JobCondition字段数据结构说明

参数

是否必选

参数类型

描述

lastProbeTime

No

String

Last time the condition was checked.

lastTransitionTime

No

String

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.

请求示例:

{
    "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"
            }
        }
    }
}

响应消息

响应参数:

响应参数的详细描述请参见表2

响应示例:

{
    "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": {}
}

状态码

表9描述API的状态码。

表9 状态码

状态码

描述

201

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

异常状态码请参见状态码

分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问