Creating a Job
Function
This API is used to create a Job.
Request
Request parameters:
For the description about request parameters, see Table 2.
|
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 |
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. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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. |
|
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 |
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 picks 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, for example, 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. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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. |
|
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. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
metadata |
Yes |
metadata object |
Standard object's metadata. |
|
spec |
Yes |
spec object |
Specification of the desired behavior of the pod. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
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. |
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.
|
Status Code |
Description |
|---|---|
|
201 |
The request has been fulfilled, resulting in the creation of a new resource. |
For the description about error status codes, see Status Code.
Last Article: Job
Next Article: Deleting a Job
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.