1
1
---
2
- title : 已完成资源的 TTL 控制器
2
+ title : 已完成 Job 的自动清理
3
3
content_type : concept
4
4
weight : 70
5
5
---
6
6
<!--
7
- title: TTL Controller for Finished Resources
7
+ title: Automatic Clean-up for Finished Jobs
8
8
content_type: concept
9
9
weight: 70
10
10
-->
11
11
12
12
<!-- overview -->
13
13
14
- {{< feature-state for_k8s_version="v1.21 " state="beta " >}}
14
+ {{< feature-state for_k8s_version="v1.23 " state="stable " >}}
15
15
16
16
<!--
17
- The TTL controller provides a TTL mechanism to limit the lifetime of resource
18
- objects that have finished execution. TTL controller only handles
19
- {{< glossary_tooltip text="Jobs" term_id="job" >}} for now,
20
- and may be expanded to handle other resources that will finish execution,
21
- such as Pods and custom resources.
17
+ TTL-after-finished {{<glossary_tooltip text="controller" term_id="controller">}} provides a
18
+ TTL (time to live) mechanism to limit the lifetime of resource objects that
19
+ have finished execution. TTL controller only handles
20
+ {{< glossary_tooltip text="Jobs" term_id="job" >}}.
22
21
-->
23
- TTL 控制器提供了一种 TTL 机制来限制已完成执行的资源对象的生命周期。
24
- TTL 控制器目前只处理 {{< glossary_tooltip text="Job" term_id="job" >}},
25
- 可能以后会扩展以处理将完成执行的其他资源,例如 Pod 和自定义资源。
22
+ TTL-after-finished {{<glossary_tooltip text="控制器" term_id="controller">}} 提供了一种 TTL 机制来限制已完成执行的资源对象的生命周期。
23
+ TTL 控制器目前只处理 {{< glossary_tooltip text="Job" term_id="job" >}}。
26
24
27
- <!--
28
- This feature is currently beta and enabled by default, and can be disabled via
29
- [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
30
- `TTLAfterFinished` in both kube-apiserver and kube-controller-manager.
31
- -->
32
- 此功能目前是 Beta 版而自动启用,并且可以通过 ` kube-apiserver ` 和
33
- ` kube-controller-manager ` 上的
34
- [ 特性门控] ( /zh/docs/reference/command-line-tools-reference/feature-gates/ )
35
- ` TTLAfterFinished ` 禁用。
36
25
37
26
<!-- body -->
38
27
39
28
<!--
40
- ## TTL Controller
29
+ ## TTL-after-finished Controller
41
30
42
- The TTL controller only supports Jobs for now . A cluster operator can use this feature to clean
31
+ The TTL-after-finished controller is only supported for Jobs . A cluster operator can use this feature to clean
43
32
up finished Jobs (either `Complete` or `Failed`) automatically by specifying the
44
33
`.spec.ttlSecondsAfterFinished` field of a Job, as in this
45
34
[example](/docs/concepts/workloads/controllers/job/#clean-up-finished-jobs-automatically).
46
35
-->
47
- ## TTL 控制器
36
+ ## TTL-after-finished 控制器
48
37
49
- TTL 控制器现在只支持 Job。集群操作员可以通过指定 Job 的 ` .spec.ttlSecondsAfterFinished `
38
+ TTL-after-finished 控制器只支持 Job。集群操作员可以通过指定 Job 的 ` .spec.ttlSecondsAfterFinished `
50
39
字段来自动清理已结束的作业(` Complete ` 或 ` Failed ` ),如
51
40
[ 示例] ( /zh/docs/concepts/workloads/controllers/job/#clean-up-finished-jobs-automatically )
52
41
所示。
53
42
54
43
<!--
55
- The TTL controller will assume that a resource is eligible to be cleaned up
56
- TTL seconds after the resource has finished, in other words, when the TTL has expired. When the
57
- TTL controller cleans up a resource , it will delete it cascadingly, i.e. delete
58
- its dependent objects together with it. Note that when the resource is deleted,
44
+ The TTL-after-finished controller will assume that a job is eligible to be cleaned up
45
+ TTL seconds after the job has finished, in other words, when the TTL has expired. When the
46
+ TTL-after-finished controller cleans up a job , it will delete it cascadingly, that is to say it will delete
47
+ its dependent objects together with it. Note that when the job is deleted,
59
48
its lifecycle guarantees, such as finalizers, will be honored.
60
49
-->
61
- TTL 控制器假设资源能在执行完成后的 TTL 秒内被清理,也就是当 TTL 过期后。
62
- 当 TTL 控制器清理资源时 ,它将做级联删除操作,即删除资源对象的同时也删除其依赖对象。
50
+ TTL-after-finished 控制器假设作业能在执行完成后的 TTL 秒内被清理,也就是当 TTL 过期后。
51
+ 当 TTL 控制器清理作业时 ,它将做级联删除操作,即删除资源对象的同时也删除其依赖对象。
63
52
注意,当资源被删除时,由该资源的生命周期保证其终结器(Finalizers)等被执行。
64
53
65
54
<!--
@@ -69,67 +58,63 @@ The TTL seconds can be set at any time. Here are some examples for setting the
69
58
可以随时设置 TTL 秒。以下是设置 Job 的 ` .spec.ttlSecondsAfterFinished ` 字段的一些示例:
70
59
71
60
<!--
72
- * Specify this field in the resource manifest, so that a Job can be cleaned up
61
+ * Specify this field in the job manifest, so that a Job can be cleaned up
73
62
automatically some time after it finishes.
74
- * Set this field of existing, already finished resources , to adopt this new feature.
63
+ * Set this field of existing, already finished jobs , to adopt this new feature.
75
64
* Use a
76
65
[mutating admission webhook](/docs/reference/access-authn-authz/extensible-admission-controllers/#admission-webhooks)
77
- to set this field dynamically at resource creation time. Cluster administrators can
78
- use this to enforce a TTL policy for finished resources .
66
+ to set this field dynamically at job creation time. Cluster administrators can
67
+ use this to enforce a TTL policy for finished jobs .
79
68
* Use a
80
69
[mutating admission webhook](/docs/reference/access-authn-authz/extensible-admission-controllers/#admission-webhooks)
81
- to set this field dynamically after the resource has finished, and choose
82
- different TTL values based on resource status, labels, etc.
70
+ to set this field dynamically after the job has finished, and choose
71
+ different TTL values based on job status, labels, etc.
83
72
-->
84
- * 在资源清单 (manifest)中指定此字段,以便 Job 在完成后的某个时间被自动清除。
85
- * 将此字段设置为现有的、已完成的资源 ,以采用此新功能。
86
- * 在创建资源时使用 [ mutating admission webhook] ( /zh/docs/reference/access-authn-authz/extensible-admission-controllers/#admission-webhooks )
87
- 动态设置该字段。集群管理员可以使用它对完成的资源强制执行 TTL 策略。
73
+ * 在作业清单 (manifest)中指定此字段,以便 Job 在完成后的某个时间被自动清除。
74
+ * 将此字段设置为现有的、已完成的作业 ,以采用此新功能。
75
+ * 在创建作业时使用 [ mutating admission webhook] ( /zh/docs/reference/access-authn-authz/extensible-admission-controllers/#admission-webhooks )
76
+ 动态设置该字段。集群管理员可以使用它对完成的作业强制执行 TTL 策略。
88
77
* 使用 [ mutating admission webhook] ( /zh/docs/reference/access-authn-authz/extensible-admission-controllers/#admission-webhooks )
89
- 在资源完成后动态设置该字段,并根据资源状态 、标签等选择不同的 TTL 值。
78
+ 在作业完成后动态设置该字段,并根据作业状态 、标签等选择不同的 TTL 值。
90
79
91
80
<!--
92
81
## Caveat
93
82
94
83
### Updating TTL Seconds
95
84
96
85
Note that the TTL period, e.g. `.spec.ttlSecondsAfterFinished` field of Jobs,
97
- can be modified after the resource is created or has finished. However, once the
86
+ can be modified after the job is created or has finished. However, once the
98
87
Job becomes eligible to be deleted (when the TTL has expired), the system won't
99
88
guarantee that the Jobs will be kept, even if an update to extend the TTL
100
89
returns a successful API response.
101
90
-->
102
91
## 警告
103
92
104
- ### 更新 TTL 秒
93
+ ### 更新 TTL 秒数
105
94
106
- 请注意,在创建资源或已经执行结束后 ,仍可以修改其 TTL 周期,例如 Job 的
95
+ 请注意,在创建 Job 或已经执行结束后 ,仍可以修改其 TTL 周期,例如 Job 的
107
96
` .spec.ttlSecondsAfterFinished ` 字段。
108
97
但是一旦 Job 变为可被删除状态(当其 TTL 已过期时),即使您通过 API 增加其 TTL
109
98
时长得到了成功的响应,系统也不保证 Job 将被保留。
110
99
111
100
<!--
112
101
### Time Skew
113
102
114
- Because TTL controller uses timestamps stored in the Kubernetes resources to
103
+ Because TTL-after-finished controller uses timestamps stored in the Kubernetes resources to
115
104
determine whether the TTL has expired or not, this feature is sensitive to time
116
- skew in the cluster, which may cause TTL controller to clean up resource objects
105
+ skew in the cluster, which may cause TTL-after-finished controller to clean up resource objects
117
106
at the wrong time.
118
107
-->
119
108
### 时间偏差 {#time-skew}
120
109
121
- 由于 TTL 控制器使用存储在 Kubernetes 资源中的时间戳来确定 TTL 是否已过期,
122
- 因此该功能对集群中的时间偏差很敏感,这可能导致 TTL 控制器在错误的时间清理资源对象。
110
+ 由于 TTL-after-finished 控制器使用存储在 Kubernetes 资源中的时间戳来确定 TTL 是否已过期,
111
+ 因此该功能对集群中的时间偏差很敏感,这可能导致 TTL-after-finished 控制器在错误的时间清理资源对象。
123
112
124
113
<!--
125
- In Kubernetes, it's required to run NTP on all nodes
126
- (see [#6159](https://github.com/kubernetes/kubernetes/issues/6159#issuecomment-93844058))
127
- to avoid time skew. Clocks aren't always correct, but the difference should be
114
+ Clocks aren't always correct, but the difference should be
128
115
very small. Please be aware of this risk when setting a non-zero TTL.
129
116
-->
130
- 在 Kubernetes 中,需要在所有节点上运行 NTP(参见
131
- [ #6159 ] ( https://github.com/kubernetes/kubernetes/issues/6159#issuecomment-93844058 ) )
132
- 以避免时间偏差。时钟并不总是如此正确,但差异应该很小。
117
+ 时钟并不总是如此正确,但差异应该很小。
133
118
设置非零 TTL 时请注意避免这种风险。
134
119
135
120
## {{% heading "whatsnext" %}}
0 commit comments