Name: pi Namespace: default Selector: batch.kubernetes.io/ controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c Labels: batch.kubernetes.io/ controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c batch.kubernetes.io/ job-name=pi ... Annotations: batch.kubernetes.io/ job-tracking: "" Parallelism: 1 Completions: 1 Start Time: Mon, 02 Dec 2019 15:20:11 +0200 Completed At: Mon, 02 Dec 2019 15:21:16 +0200 Duration: 65s Pods Statuses: 0 Running/ 1 Succeeded/ 0 Failed Pod Template: Labels: batch.kubernetes.io/ controller-uid=c9948307-e56d-4b5d-8302-ae2d7b7da67c batch.kubernetes.io/ job-name=pi Containers: pi: Image: perl:5.34.0 Port: Host Port: Command: perl -Mbignum=bpi -wle print bpi( 2000) Environment: Mounts: Volumes: Events: Type Reason Age From Message-- ---------- ------- Normal SuccessfulCreate 21s job-controller Created pod: pi-xf9p4 Normal Completed 18s job-controller Job finished
apiVersion: batch/v1 kind: Job metadata: annotations: batch.kubernetes.io/ job-tracking: "" ... creationTimestamp: "2022-11-10T17:53:53 Z" generation: 1 labels: batch.kubernetes.io/ controller-uid: 863452e6-270d-420e-9b94-53a54146c223 batch.kubernetes.io/ job-name: pi name: pi namespace: default resourceVersion: "4751" uid: 204fb678-040b-497f-9266-35ffa8716d14 spec: backoffLimit: 4 completionMode: NonIndexed conclusions: 1 parallelism: 1 selector: matchLabels: batch.kubernetes.io/ controller-uid: 863452e6-270d-420e-9b94-53a54146c223 suspend: false design template: metadata: creationTimestamp: null labels: batch.kubernetes.io/ controller-uid: 863452e6-270d-420e-9b94-53a54146c223 batch.kubernetes.io/ job-name: pi spec: containers: - command: - perl - -Mbignum=bpi - -wle - print bpi( 2000) image: perl:5.34.0 imagePullPolicy: IfNotPresent name: pi resources: terminationMessagePath:/ dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Never schedulerName: default-scheduler securityContext: terminationGracePeriodSeconds: 30 status: active: 1 prepared: 0 startTime: "2022-11-10T17:53:57 Z" uncountedTerminatedPods:
To view completed Pods of a Job, utilize kubectl get pods.
To list all the Pods that come from a Task in a machine understandable kind, you can use a command like this:
Here, the selector is the very same as the selector for the Job. The-- output=jsonpath alternative defines an expression with the name from each Pod in the returned list.
View the standard output of among the pods:
Another method to see the logs of a Task:
The output is comparable to this:
Writing a Task spec
As with all other Kubernetes config, a Job needs apiVersion, kind, and metadata fields.
When the control airplane produces new Pods for a Job, the.metadata.name of the Job belongs to the basis for naming those Pods. The name of a Job need to be a valid DNS value, however this can produce unexpected outcomes for the Pod hostnames. For finest compatibility, the name must follow the more limiting guidelines for a DNS label. Even when the name is a DNS subdomain, the name needs to be no longer than 63 characters.
A Task likewise requires a.spec section.
Job Labels
Job labels will have batch.kubernetes.io/ prefix for job-name and controller-uid.
Pod Template
The.spec.template is the only required field of the.spec.
The.spec.template is a pod design template. It has precisely the very same schema as a Pod, except it is embedded and does not have an apiVersion or kind.
In addition to required fields for a Pod, a pod template in a Task must define proper labels (see pod selector) and an appropriate reboot policy.
Only a RestartPolicy equivalent to Never or OnFailure is allowed.
Pod selector
The.spec.selector field is optional. In nearly all cases you must not specify it. See area specifying your own pod selector.
Parallel execution for Jobs
There are three primary types of task ideal to run as a Task:
1. Non-parallel Jobs- usually, just one Pod is begun, unless the Pod stops working.
- the Job is total as quickly as its Pod terminates effectively.
2. Parallel Jobs with a fixed completion count:- define a non-zero favorable value for.spec.completions.
- the Job represents the overall task, and is complete when there are.spec.completions successful Pods.
- when using.spec.completionMode="Indexed", each Pod gets a various index in the variety 0 to.spec.completions-1.
3. Parallel Jobs with a work line:- do not specify.spec.completions, default to.spec.parallelism.
- the Pods should coordinate amongst themselves or an external service to determine what each ought to deal with. For instance, a Pod might fetch a batch of as much as N products from the work line.
- each Pod is individually efficient in determining whether or not all its peers are done, and therefore that the whole Job is done.
- when any Pod from the Job ends with success, no brand-new Pods are created.
- once a minimum of one Pod has actually terminated with success and all Pods are ended, then the Job is completed with success.
- when any Pod has actually left with success, no other Pod must still be doing any work for this job or composing any output. They need to all be in the procedure of exiting.
For a non-parallel Job, you can leave both.spec.completions and.spec.parallelism unset. When both are unset, both are defaulted to 1.
For a repaired completion count Job, you should set.spec.completions to the variety of conclusions required. You can set.spec.parallelism, or leave it unset and it will default to 1.
For a work queue Job, you should leave.spec.completions unset, and set.spec.parallelism to a non-negative integer.
For more details about how to utilize the various types of job, see the task patterns section.
Controlling parallelism
The requested parallelism (. spec.parallelism) can be set to any non-negative worth. If it is undefined, it defaults to 1. If it is defined as 0, then the Job is efficiently paused till it is increased.
Actual parallelism (number of pods performing at any immediate) might be more or less than requested parallelism, for a range of factors:
- For repaired completion count Jobs, the actual number of pods running in parallel will not surpass the variety of staying completions. Higher values of.spec.parallelism are successfully disregarded.
- For work line Jobs, no new Pods are begun after any Pod has actually been successful-- staying Pods are enabled to complete, nevertheless.
- If the Job Controller has not had time to react.
- If the Job controller failed to develop Pods for any reason (lack of ResourceQuota, absence of consent, etc), then there might be fewer pods than requested.
- The Job controller may throttle brand-new Pod development due to excessive previous pod failures in the very same Job.
- When a Pod is gracefully closed down, it takes some time to stop.
Completion mode
Jobs with set completion count - that is, jobs that have non null.spec.completions - can have a completion mode that is defined in.spec.completionMode:
NonIndexed (default): the Job is considered complete when there have been.spec.completions successfully completed Pods. In other words, each Pod conclusion is homologous to each other. Note that Jobs that have null.spec.completions are implicitly NonIndexed.
Indexed: the Pods of a Task get an associated completion index from 0 to.spec.completions-1. The index is available through four mechanisms:
- The Pod annotation batch.kubernetes.io/ job-completion-index.
- The Pod label batch.kubernetes.io/ job-completion-index (for v1.28 and later). Note the feature gate PodIndexLabel must be made it possible for to utilize this label, and it is enabled by default.
- As part of the Pod hostname, following the pattern $(job-name)-$(index). When you use an Indexed Job in combination with a Service, Pods within the Job can use the deterministic hostnames to deal with each other by means of DNS. To learn more about how to configure this, see Job with Pod-to-Pod Communication.
- From the containerized job, in the environment variable JOB_COMPLETION_INDEX.
The Job is thought about complete when there is one effectively finished Pod for each index. For more details about how to use this mode, see Indexed Job for Parallel Processing with Static Work Assignment.