Reputation: 183
Is there a way for a Deployment
or Job
to completely delete itself upon completion?
I want it such that when I do kubectl get jobs/deployments/pods
they don't show up after they finished (container exited).
One possible way I thought of was to call kubectl delete jobs/deployments/pods
from within the container but I'm not sure if that's safe.
Upvotes: 1
Views: 1550
Reputation: 874
I found a related question and answer, but found out it is for CronJobs
.
Following that answer, there is a TTL Controller introduced Alpha
in 1.12
and Beta
in 1.21
.
You have to manually enable it in Feature Gates before v1.21
.
According to the docs:
provides a TTL (time to live) 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.
It could clean up Jobs
currently and others in plan.
Upvotes: 1