Skip to content

Commit 6c4a676

Browse files
committed
JobPodReplacementPolicy Promoted To GA Blog Post
Signed-off-by: Dejan Zele Pejchev <pejcev.dejan@gmail.com>
1 parent 35b1ebe commit 6c4a676

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
layout: blog
3+
title: "Kubernetes 1.34: Pod Replacement Policy for Jobs Goes GA"
4+
date: 2025-06-29
5+
slug: kubernetes-1-34-pod-replacement-policy-for-jobs-goes-ga
6+
author: >
7+
[Dejan Zele Pejchev](https://github.com/dejanzele) (G-Research)
8+
---
9+
10+
In Kubernetes v1.34, the _Pod Replacement Policy_ feature reaches general availability (GA).
11+
This blog post describes the Pod Replacement Policy feature and how to use it in your Jobs.
12+
13+
## About Pod Replacement Policy
14+
15+
By default, the Job controller immediately recreates Pods as soon as they fail or begin terminating (when they have a deletion timestamp).
16+
17+
As a result, while some Pods are terminating, the total number of running Pods for a Job can temporarily exceed the specified parallelism.
18+
For Indexed Jobs, this can even mean multiple Pods running for the same index at the same time.
19+
20+
This behavior works fine for many workloads, but it can cause problems in certain cases.
21+
22+
For example, popular machine learning frameworks like TensorFlow and
23+
[JAX](https://jax.readthedocs.io/en/latest/) expect exactly one Pod per worker index.
24+
If two Pods run at the same time, you might encounter errors such as:
25+
```
26+
/job:worker/task:4: Duplicate task registration with task_name=/job:worker/replica:0/task:4
27+
```
28+
29+
Another example is in clusters with limited or expensive resources.
30+
Starting replacement Pods before the old ones fully terminate can lead to scheduling delays or even unnecessary cluster scale-ups.
31+
32+
The _Pod Replacement Policy_ feature gives you control over when Kubernetes replaces terminating Pods, helping you avoid these issues.
33+
34+
## How Pod Replacement Policy works
35+
36+
The feature introduces a new Job-level field, `podReplacementPolicy`, which controls when Kubernetes replaces terminating Pods.
37+
You can choose one of two policies:
38+
39+
- TerminatingOrFailed (default): Replaces Pods as soon as they start terminating.
40+
- Failed: Replaces Pods only after they fully terminate and transition to the `Failed` phase.
41+
42+
Setting the policy to `Failed` ensures that a new Pod is only created after the previous one has completely terminated.
43+
44+
For Jobs with a Pod Failure Policy, the default `podReplacementPolicy` is `Failed`, and no other value is allowed.
45+
See [Pod Failure Policy](/docs/concepts/workloads/controllers/job/#pod-failure-policy) to learn more about Pod Failure Policies for Jobs.
46+
47+
You can check how many Pods are currently terminating by inspecting the Job’s `.status.terminating` field:
48+
49+
```sh
50+
kubectl get job myjob -o=jsonpath='{.status.terminating}'
51+
```
52+
53+
For external queueing controllers such as [Kueue](https://github.com/kubernetes-sigs/kueue),
54+
this distinction matters because resources aren’t considered “freed” until terminating Pods are fully cleaned up.
55+
56+
## Example
57+
58+
Here’s a simple Job spec that ensures Pods are replaced only after they terminate completely:
59+
60+
```yaml
61+
apiVersion: batch/v1
62+
kind: Job
63+
metadata:
64+
name: example-job
65+
spec:
66+
podReplacementPolicy: Failed
67+
template:
68+
spec:
69+
restartPolicy: Never
70+
containers:
71+
- name: worker
72+
image: your-image
73+
```
74+
75+
With this setting, Kubernetes won’t launch a replacement Pod while the previous Pod is still terminating.
76+
77+
## How can you learn more?
78+
79+
- Read the user-facing documentation for [Pod Replacement Policy](/docs/concepts/workloads/controllers/job/#pod-replacement-policy),
80+
[Backoff Limit per Index](/docs/concepts/workloads/controllers/job/#backoff-limit-per-index)and
81+
[Pod Failure Policy](/docs/concepts/workloads/controllers/job/#pod-failure-policy).
82+
- Read the KEPs for [Pod Replacement Policy](https://github.com/kubernetes/enhancements/tree/master/keps/sig-apps/3939-allow-replacement-when-fully-terminated),
83+
[Backoff Limit per Index](https://github.com/kubernetes/enhancements/tree/master/keps/sig-apps/3850-backoff-limits-per-index-for-indexed-jobs), and
84+
[Pod Failure Policy](https://github.com/kubernetes/enhancements/tree/master/keps/sig-apps/3329-retriable-and-non-retriable-failures).
85+
86+
87+
## Acknowledgments
88+
89+
As with any Kubernetes feature, multiple people contributed to getting this
90+
done, from testing and filing bugs to reviewing code.
91+
92+
As this feature moves to stable after 2 years, we would like to thank the following people:
93+
* [Kevin Hannon](https://github.com/kannon92) - for writing the KEP and the initial implementation.
94+
* [Michał Woźniak](https://github.com/mimowo) - for guidance, mentorship, and reviews.
95+
* [Aldo Culquicondor](https://github.com/alculquicondor) - for guidance, mentorship, and reviews.
96+
* [Maciej Szulik](https://github.com/soltysh) - for guidance, mentorship, and reviews.
97+
* [Dejan Zele Pejchev](https://github.com/dejanzele) - for taking over the feature and promoting it from Alpha through Beta to GA.
98+
99+
## Get involved
100+
101+
This work was sponsored by the Kubernetes
102+
[batch working group](https://github.com/kubernetes/community/tree/master/wg-batch)
103+
in close collaboration with the
104+
[SIG Apps](https://github.com/kubernetes/community/tree/master/sig-apps) community.
105+
106+
If you are interested in working on new features in the space we recommend
107+
subscribing to our [Slack](https://kubernetes.slack.com/messages/wg-batch)
108+
channel and attending the regular community meetings.

0 commit comments

Comments
 (0)