简体   繁体   English

Kubernetes作业完成后删除Pod的最佳方法是什么

[英]What is the best way to delete a Pod after a Kubernetes Job completes

I have a situation in which I run a Kubernetes Job and then want to delete the pod in which the Job's containers run when the job completes. 我遇到的情况是,我运行一个Kubernetes作业,然后想在作业完成时删除运行作业容器的pod。 The Kubernetes documentation says the it is the responsibility of the user to delete the pod. Kubernetes文档说 ,删除Pod是用户的责任。

However, my goal is to run a CPU intensive job by spinning up a big honking pod, let the job run, and then upon job completion, automagically nuke the pod. 但是,我的目标是通过旋转一个巨大的喇叭吊舱来运行CPU密集型作业,让该作业运行,然后在作业完成后自动对吊舱进行核对。 My thinking is that paying for an expensive, resource intensive pod is worth it when the revenue producing job runs. 我的想法是,当产生收入的工作运行时,为昂贵的资源密集型平台支付费用是值得的。 Once the job is over, the revenue stream ends and I need to cut the expense, hence nuking the pod. 一旦工作结束,收入流就结束了,我需要削减费用,因此给豆荚带来麻烦。

I am thinking of having my code in the job container send a out a message upon program completion to a publisher that is picked up by a subscriber. 我正在考虑让我的代码在作业容器中,在程序完成后向订阅者选择的发布者发送一条消息。 The subscriber knows how to run the command, kubectl delete jobs/myContainer to nuke the pod. 订户知道如何运行该命令, kubectl delete jobs/myContainer来吊舱。

But, maybe there is a better way. 但是,也许有更好的方法。 Thus, I ask. 因此,我问。

Thanks in advance. 提前致谢。

Why would you need to delete the pod at all ? 为什么您需要完全删除Pod? If the job completed successfully (exit code 0) then the pod will be completed, it will no longer use cpu/memory resurces, and should be garbage collected when needed. 如果作业成功完成(退出代码0),则pod将完成,它将不再使用cpu /内存资源,应在需要时进行垃圾回收。

There is a new API that delete jobs after completion and all the dependent elements. 有一个新的API,可在完成作业和所有相关元素后删除作业。 The TTLAfterFinished . TTLAfterFinished

You can define it in the .spec.ttlSecondsAfterFinished property of your job. 您可以在作业的.spec.ttlSecondsAfterFinished属性中定义它。 The cleanup will happen X seconds after the job is completed or failed. 清理将在作业完成或失败后X秒钟进行。

As of 16, March, 2019, this API is in alpha, with version 1.12 and can only be used with alpha features enabled. 自2019年3月16日起,此API处于Alpha版本,版本为1.12,并且只能在启用Alpha功能的情况下使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM