Is it possible to enable TTL controller in aks cluster for job automatic deletion

2/3/2022

I want to delete completed jobs in my aks cluster after certain time interval using TTL controller, but I'm unable to enable TTL controller in aks cluster, Is there any solution for this problem... Thanks in advance...

-- harish hari
azure-aks
devops
kubernetes
kubernetes-jobs

1 Answer

2/3/2022

TTL in AKS is available since 1.21.2 version of Kubernetes. For more look at this github topic:

Short update on that. It is available in 1.21.2. Got the confirmation from Azure Support. So, we are currently using it.

Make sure that you are using this or newer version. For older versions, you won't be able to run this mechanism. You can also use kube-cleanup operator for older versions of cluster.

Here you can find information how to enable TTL on AKS cluster:

Another way to clean up finished Jobs (either Complete or Failed) automatically is to use a TTL mechanism provided by a TTL controller for finished resources, by specifying the .spec.ttlSecondsAfterFinished field of the Job.

Reference

When the TTL controller cleans up the Job, it will delete the Job cascadingly, i.e. delete its dependent objects, such as Pods, together with the Job. Note that when the Job is deleted, its lifecycle guarantees, such as finalizers, will be honored.

So this could help you to enable TTL mechanism on your cluster.

-- Mikołaj Głodziak
Source: StackOverflow