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 completed
obsproject.com
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: incorrect 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 all set: 0 startTime: "2022-11-10T17:53:57 Z" uncountedTerminatedPods:
To see finished Pods of a Job, use kubectl get pods.
To note all the Pods that come from a Job in a machine legible form, you can utilize a command like this:
Here, the selector is the exact same as the selector for the Job. The-- output=jsonpath option defines an expression with the name from each Pod in the returned list.
View the basic output of one of the pods:
Another method to see the logs of a Task:
The output is similar to this:
Writing a Task spec
Similar to all other Kubernetes config, a Task requires apiVersion, kind, and metadata fields.
When the control plane produces brand-new Pods for a Job, the.metadata.name of the Job becomes part of the basis for calling those Pods. The name of a Task need to be a valid DNS subdomain value, but this can produce unexpected outcomes for the Pod hostnames. For best compatibility, the name must follow the more restrictive rules for a DNS label. Even when the name is a DNS subdomain, the name must be no longer than 63 characters.
A Job likewise requires a.spec area.
Job Labels
Job labels will have batch.kubernetes.io/ prefix for job-name and controller-uid.
Pod Template
The.spec.template is the only necessary field of the.spec.
The.spec.template is a pod design template. It has exactly the same schema as a Pod, other than it is embedded and does not have an apiVersion or kind.
In addition to needed fields for a Pod, a pod template in a Job should define appropriate labels (see pod selector) and an appropriate restart policy.
Only a RestartPolicy equal to Never or OnFailure is permitted.
Pod selector
The.spec.selector field is optional. In practically all cases you ought to not define it. See area defining your own pod selector.
Parallel execution for Jobs
There are three primary types of task suitable to run as a Task:
1. Non-parallel Jobs- usually, just one Pod is begun, unless the Pod stops working.
- the Job is complete as quickly as its Pod terminates successfully.
2. Parallel Jobs with a repaired conclusion count:- specify a non-zero favorable worth for.spec.completions.
- the Job represents the total task, and is total when there are.spec.completions effective Pods.
- when using.spec.completionMode="Indexed", each Pod gets a different index in the range 0 to.spec.completions-1.
3. Parallel Jobs with a work queue:- do not specify.spec.completions, default to.spec.parallelism.
- the Pods must collaborate amongst themselves or an external service to determine what each need to deal with. For instance, a Pod may fetch a batch of up to N products from the work queue.
- each Pod is independently capable of determining whether all its peers are done, and thus that the entire Job is done.
- when any Pod from the Job ends with success, no new Pods are created.
- once a minimum of one Pod has actually ended with success and all Pods are ended, then the Job is finished with success.
- once any Pod has actually left with success, no other Pod needs to still be doing any work for this job or writing any output. They should all remain in the procedure of leaving.
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 fixed completion count Job, you should set.spec.completions to the variety of completions required. You can set.spec.parallelism, or leave it unset and it will default to 1.
For a work line Job, you must leave.spec.completions unset, and set.spec.parallelism to a non-negative integer.
For more details about how to utilize the different types of task, see the task patterns area.
Controlling parallelism
The asked for parallelism (. spec.parallelism) can be set to any non-negative value. If it is undefined, it defaults to 1. If it is specified as 0, then the Job is effectively stopped briefly until it is increased.
Actual parallelism (variety of pods running at any immediate) may be basically than requested parallelism, for a variety of reasons:
- For repaired conclusion count Jobs, the actual number of pods running in parallel will not surpass the variety of remaining completions. Higher worths of.spec.parallelism are effectively neglected.
- For work line Jobs, no new Pods are begun after any Pod has actually prospered-- staying Pods are enabled to complete, however.
- If the Job Controller has not had time to respond.
- If the Job controller failed to create Pods for any reason (lack of ResourceQuota, absence of approval, etc), then there may be less pods than asked for.
- The Job controller may throttle brand-new Pod production due to excessive previous pod failures in the exact same Job.
- When a Pod is with dignity shut down, it requires time to stop.
Completion mode
Jobs with count - that is, tasks that have non null.spec.completions - can have a completion mode that is specified in.spec.completionMode:
NonIndexed (default): the Job is considered total when there have actually been.spec.completions successfully finished Pods. Simply put, each Pod completion is homologous to each other. Note that Jobs that have null.spec.completions are implicitly NonIndexed.
obsproject.com
Indexed: the Pods of a Job get an associated conclusion index from 0 to.spec.completions-1. The index is readily available through four systems:
- 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 should be made it possible for to utilize this label, and it is allowed by default.
- As part of the Pod hostname, following the pattern $(job-name)-$(index). When you utilize an Indexed Job in mix with a Service, Pods within the Job can utilize the deterministic hostnames to attend to each other via DNS. For more information about how to configure this, see Job with Pod-to-Pod Communication.
- From the containerized task, in the environment variable JOB_COMPLETION_INDEX.
The Job is thought about complete when there is one effectively finished Pod for each index. For additional information about how to utilize this mode, see Indexed Job for Parallel Processing with Static Work Assignment.
1
For A Fixed Completion Count Job
seanlandry413 edited this page 1 month ago