instruction: Create a Dockerfile for workloads
output: ```dockerfile
  from a Job are stuck with the tracking finalizer.
  Elastic Indexed Jobs
  
  FEATURE STATE:
  Kubernetes v1.31 [stable] (enabled by default: true)
  
  You can scale Indexed Jobs up or down by mutating both .spec.parallelism
  and .spec.completions together such that .spec.parallelism == .spec.completions.
  When scaling down, Kubernetes removes the Pods with higher indexes.
  Use cases for elastic Indexed Jobs include batch workloads which require
  scaling an indexed Job, such as MPI, Horovod, Ray, and PyTorch training jobs.
  Delayed creation of replacement pods
  
  FEATURE STATE:
  Kubernetes v1.29 [beta]
  
  Note:You can only set podReplacementPolicy on Jobs if you enable the JobPodReplacementPolicy
  feature gate
  (enabled by default).
  By default, the Job controller recreates Pods as soon they either fail or are terminating (have a deletion timestamp).
  This means that, at a given time, when some of the Pods are terminating, the number of running Pods for a Job
  can be greater than parallelism or greater than one Pod per index (if you are using an Indexed Job).
  You may choose to create replacement Pods only when the terminating Pod is fully terminal (has status.phase: Failed).
  To do this, set the .spec.podReplacementPolicy: Failed.
  The default replacement policy depends on whether the Job has a podFailurePolicy set.
  With no Pod failure policy defined for a Job, omitting the podReplacementPolicy field selects the
  TerminatingOrFailed replacement policy:
  the control plane creates replacement Pods immediately upon Pod deletion
  (as soon as the control plane sees that a Pod for this Job has deletionTimestamp set).
  For Jobs with a Pod failure policy set, the default podReplacementPolicy is Failed, and no other
  value is permitted.
  See Pod failure policy to learn more about Pod failure policies for Jobs.
  kind: Job
  metadata:
   name: new
   ...
  spec:
   podReplacementPolicy: Failed
   ...
  Provided your cluster has the feature gate enabled, you can inspect the .status.terminating field of a Job.
  The value of the field is the number of Pods owned by the Job that are currently terminating.
  kubectl get jobs/myjob -o yaml
  apiVersion: batch/v1
  kind: Job
  # .metadata and .spec omitted
  status:
   terminating: 3 # three Pods are terminating and have not yet reached the Failed phase
  Delegation of managing a Job object to external controller
  
  FEATURE STATE:
  Kubernetes v1.30 [alpha] (enabled by default: false)
  
  Note:You can only set the managedBy field on Jobs if you enable the JobManagedBy
  feature gate
  (disabled by default).
  This feature allows you to disable the built-in Job controller, for a specific
  Job, and delegate reconciliation of the Job to an external controller.
  You indicate the controller that reconciles the Job by setting a custom value
  for the spec.managedBy field - any value
  other than kubernetes.io/job-controller. The value of the field is immutable.
  Note:When using this feature, make sure the controller indicated by the field is
  installed, otherwise the Job may not be reconciled at all.
  Note:When developing an external Job controller be aware that your controller needs
  to operate in a fashion conformant with the definitions of the API spec and
  status fields of the Job object.
  Please review these in detail in the Job API.
  We also recommend that you run the e2e conformance tests for the Job object to
  verify your implementation.
  Finally, when developing an external Job controller make sure it does not use the
  batch.kubernetes.io/job-tracking finalizer, reserved for the built-in controller.
  
  Warning:If you are considering to disable the JobManagedBy feature gate, or to
  downgrade the cluster to a version without the feature gate enabled, check if
  there are jobs with a custom value of the spec.managedBy field. If there
  are such jobs, there is a risk that they might be reconciled by two controllers
  after the operation: the built-in Job controller and the external controller
  indicated by the field value.
  Alternatives
  Bare Pods
  When the node that a Pod is running on reboots or fails, the pod is terminated
  and will not be restarted. However, a Job will create new Pods to replace terminated ones.
  For this reason, we recommend that you use a Job rather than a bare Pod, even if your application
  requires only a single Pod.
  Replication Controller
  Jobs are complementary to Replication Controllers.
  A Replication Controller manages Pods which are not expected to terminate (e.g. web servers), and a Job
  manages Pods that are expected to terminate (e.g. batch tasks).
  As discussed in Pod Lifecycle, Job is only appropriate
  for pods with RestartPolicy equal to OnFailure or Never.
  (Note: If RestartPolicy is not set, the default value is Always.)
  Single Job starts controller Pod
  Another pattern is for a single Job to create a Pod which then creates other Pods, acting as a sort
  of custom controller for those Pods. This allows the most flexibility, but may be somewhat
  complicated to get started with and offers less integration with Kubernetes.
  One example of this pattern would be a Job which starts a Pod which runs a script that in turn
  starts a Spark master controller (see spark example),
  runs a spark driver, and then cleans up.
  An advantage of this approach is that the overall process gets the completion guarantee of a Job
  object, but maintains complete control over what Pods are created and how work is assigned to them.
  What's next
  
  Learn about Pods.
  Read about different ways of running Jobs:
  
  Coarse Parallel Processing Using a Work Queue
  Fine Parallel Processing Using a Work Queue
  Use an indexed Job for parallel processing with static work assignment
  Create multiple Jobs based on a template: Parallel Processing using Expansions
  
  Follow the links within Clean up finished jobs automatically
  to learn more about how your cluster can clean up completed and / or failed tasks.
  Job is part of the Kubernetes REST API.
  Read the
  
  Job
  object definition to understand the API for jobs.
  Read about CronJob, which you
  can use to define a series of Jobs that will run based on a schedule, similar to
  the UNIX tool cron.
  Practice how to configure handling of retriable and non-retriable pod failures
  using podFailurePolicy, based on the step-by-step examples.
  
  Feedback
  Was this page helpful?
  Yes
  No
  
   Thanks for the feedback. If you have a specific, answerable question about how to use Kubernetes, ask it on
  
   Stack Overflow.
   Open an issue in the GitHub Repository if you want to
  
   report a problem
   or
  
   suggest an improvement.
  
   Last modified August 23, 2024 at 10:23 PM PST: Fix a typo in controllers/job.md (e694639ae2)
  
   Job API reference
    Create child page
   Create documentation issue
   Print entire section
  
  Running an example Job
  Writing a Job spec
  
  Job Labels
  Pod Template
  Pod selector
  Parallel execution for Jobs
  Completion mode
  
  Handling Pod and container failures
  
  Pod backoff failure policy
  Backoff limit per index
  Pod failure policy
  
  Success policy
  Job termination and cleanup
  
  Terminal Job conditions
  Termination of Job pods
  
  Clean up finished jobs automatically
  
  TTL mechanism for finished Jobs
  
  Job patterns
  Advanced usage
  
  Suspending a Job
  Mutable Scheduling Directives
  Specifying your own Pod selector
  Job tracking with finalizers
  Elastic Indexed Jobs
  Delayed creation of replacement pods
  Delegation of managing a Job object to external controller
  
  Alternatives
  
  Bare Pods
  Replication Controller
  Single Job starts controller Pod
  
  What's next
  
  © 2025 The Kubernetes Authors | Documentation Distributed under CC BY 4.0
  © 2025 The Linux Foundation ®. ICP license: 京ICP备17074266号-3
  ```