You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/blog/_posts/2025-0x-xx-jobs-podreplacementpolicy-goes-ga.md
+55-6Lines changed: 55 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,8 +39,8 @@ replaces terminating Pods, helping you avoid these issues.
39
39
40
40
This enhancement means that Jobs in Kubernetes have an optional field `.spec.podReplacementPolicy`.
41
41
You can choose one of two policies:
42
-
- TerminatingOrFailed (default): Replaces Pods as soon as they start terminating.
43
-
- Failed: Replaces Pods only after they fully terminate and transition to the `Failed` phase.
42
+
-`TerminatingOrFailed` (default): Replaces Pods as soon as they start terminating.
43
+
-`Failed`: Replaces Pods only after they fully terminate and transition to the `Failed` phase.
44
44
45
45
Setting the policy to `Failed` ensures that a new Pod is only created after the previous one has completely terminated.
46
46
@@ -49,20 +49,22 @@ See [Pod Failure Policy](/docs/concepts/workloads/controllers/job/#pod-failure-p
49
49
50
50
You can check how many Pods are currently terminating by inspecting the Job’s `.status.terminating` field:
51
51
52
-
```sh
52
+
```shell
53
53
kubectl get job myjob -o=jsonpath='{.status.terminating}'
54
54
```
55
55
56
56
## Example
57
57
58
-
Here’s a simple Job spec that ensures Pods are replaced only after they terminate completely:
59
-
58
+
Here’s a Job example that executes a task two times (`spec.completions: 2`) in parallel (`spec.parallelism: 2`) and
59
+
replaces Pods only after they fully terminate (`spec.podReplacementPolicy: Failed`):
60
60
```yaml
61
61
apiVersion: batch/v1
62
62
kind: Job
63
63
metadata:
64
64
name: example-job
65
65
spec:
66
+
completions: 2
67
+
parallelism: 2
66
68
podReplacementPolicy: Failed
67
69
template:
68
70
spec:
@@ -72,7 +74,45 @@ spec:
72
74
image: your-image
73
75
```
74
76
75
-
With this setting, Kubernetes won’t launch a replacement Pod while the previous Pod is still terminating.
77
+
If a Pod receives a SIGTERM signal (deletion, eviction, preemption...), it begins terminating.
78
+
When the container handles termination gracefully, cleanup may take some time.
79
+
80
+
When the Job starts, we will see two Pods running:
81
+
```shell
82
+
kubectl get pods
83
+
84
+
NAME READY STATUS RESTARTS AGE
85
+
example-job-qr8kf 1/1 Running 0 2s
86
+
example-job-stvb4 1/1 Running 0 2s
87
+
```
88
+
89
+
With the `TerminatingOrFailed` policy, as soon as one Pod (`example-job-qr8kf`) starts terminating, the Job controller immediately creates a new Pod (`example-job-b59zk`) to replace it.
90
+
```shell
91
+
kubectl get pods
92
+
93
+
NAME READY STATUS RESTARTS AGE
94
+
example-job-b59zk 1/1 Running 0 1s
95
+
example-job-qr8kf 1/1 Terminating 0 17s
96
+
example-job-stvb4 1/1 Running 0 17s
97
+
```
98
+
99
+
With the `Failed` policy, the new Pod (`example-job-b59zk`) is not created while the old Pod (`example-job-qr8kf`) is terminating.
100
+
```shell
101
+
kubectl get pods
102
+
103
+
NAME READY STATUS RESTARTS AGE
104
+
example-job-qr8kf 1/1 Terminating 0 17s
105
+
example-job-stvb4 1/1 Running 0 17s
106
+
```
107
+
108
+
When the terminating Pod has fully transitioned to the `Failed` phase, a new Pod is created:
109
+
```shell
110
+
kubectl get pods
111
+
112
+
NAME READY STATUS RESTARTS AGE
113
+
example-job-b59zk 1/1 Running 0 1s
114
+
example-job-stvb4 1/1 Running 0 25s
115
+
```
76
116
77
117
## How can you learn more?
78
118
@@ -106,3 +146,12 @@ in close collaboration with the
106
146
If you are interested in working on new features in the space we recommend
107
147
subscribing to our [Slack](https://kubernetes.slack.com/messages/wg-batch)
108
148
channel and attending the regular community meetings.
0 commit comments