33-TTL Controller for Finished Resources

TTL Controller for Finished Resources 成品资源的TTL控制器

FEATURE STATE: Kubernetes v1.12 alpha

The TTL controller provides a TTL mechanism to limit the lifetime of resource objects that have finished execution. TTL controller only handles Jobs for now, and may be expanded to handle other resources that will finish execution, such as Pods and custom resources. ttl控制器提供了ttl机制来限制已完成执行的资源对象的生存期。TTL控制器目前只处理作业,并且可以扩展以处理将完成执行的其他资源,例如pods和自定义资源。

Alpha Disclaimer: this feature is currently alpha, and can be enabled with feature gate TTLAfterFinished. alpha免责声明:此功能当前为alpha,可通过

TTL Controller

The TTL controller only supports Jobs for now. A cluster operator can use this feature to clean up finished Jobs (either Complete or Failed) automatically by specifying the .spec.ttlSecondsAfterFinished field of a Job, as in this example. The TTL controller will assume that a resource is eligible to be cleaned up TTL seconds after the resource has finished, in other words, when the TTL has expired. When the TTL controller cleans up a resource, it will delete it cascadingly, i.e. delete its dependent objects together with it. Note that when the resource is deleted, its lifecycle guarantees, such as finalizers, will be honored. TTL控制器目前只支持作业。群集操作员可以使用此功能通过指定作业的“.spec.ttlsecondsafterfinished”字段自动清理完成的作业(“complete”或“failed”),如[示例](https://kubernetes.io/docs/concepts/worklo... run to completion/"自动清理完成的作业")。ttl控制器将假定在资源完成后的几秒钟内(换句话说,当ttl过期时),资源有资格被清理ttl。当ttl控制器清理一个资源时,它将级联删除它,也就是说,将它的从属对象一起删除。请注意,当资源被删除时,它的生命周期保证(如终结器)将得到遵守。

The TTL seconds can be set at any time. Here are some examples for setting the .spec.ttlSecondsAfterFinished field of a Job:

  • Specify this field in the resource manifest, so that a Job can be cleaned up automatically some time after it finishes.
  • Set this field of existing, already finished resources, to adopt this new feature.
  • Use a mutating admission webhook to set this field dynamically at resource creation time. Cluster administrators can use this to enforce a TTL policy for finished resources.
  • Use a mutating admission webhook to set this field dynamically after the resource has finished, and choose different TTL values based on resource status, labels, etc.

Caveat

Updating TTL Seconds

Note that the TTL period, e.g. .spec.ttlSecondsAfterFinished field of Jobs, can be modified after the resource is created or has finished. However, once the Job becomes eligible to be deleted (when the TTL has expired), the system won’t guarantee that the Jobs will be kept, even if an update to extend the TTL returns a successful API response. 请注意,ttl period,例如作业的“.spec.ttlsecondsafterfinished”字段,可以在创建或完成资源后修改。但是,一旦作业有资格被删除(当ttl过期时),系统将不保证作业将被保留,即使扩展ttl的更新返回成功的api响应。

Time Skew

Because TTL controller uses timestamps stored in the Kubernetes resources to determine whether the TTL has expired or not, this feature is sensitive to time skew in the cluster, which may cause TTL controller to clean up resource objects at the wrong time. 由于ttl控制器使用存储在kubernetes资源中的时间戳来确定ttl是否已过期,因此此功能对集群中的时间偏移敏感,这可能导致ttl控制器在错误的时间清理资源对象。

In Kubernetes, it’s required to run NTP on all nodes (see #6159) to avoid time skew. Clocks aren’t always correct, but the difference should be very small. Please be aware of this risk when setting a non-zero TTL.

What's next

Clean up Jobs automatically

Design doc

Feedback

Was this page helpful?

k8s
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!