The k8s-ttl-controller project is a Kubernetes controller which provides a time to live (TTL) mechanism for Kubernetes resources. The TTL behavior for each resource is configured through a TTLPolicy using the following user-defined parameters:
expirationFrom- the resource property used as reference point from which expiration is calculated. If not specified, it defaults to the resource's creation timettlFromthe resource property used as the TTL value
Install the CRD using:
kubectl apply -f https://raw.githubusercontent.com/fpetkovski/k8s-ttl-controller/0.6.0/deploy/crds.yamland the controller using:
kubectl apply -f https://raw.githubusercontent.com/fpetkovski/k8s-ttl-controller/0.6.0/deploy/controller.yamlExpiring Kubernetes jobs in the Completed state can be done by creating a TTLPolicy with the following configuration:
apiVersion: fpetkovski.io/v1alpha1
kind: TTLPolicy
metadata:
name: jobs-ttl-controller
spec:
resource:
apiVersion: batch/v1
kind: Job
expirationFrom: .status.completionTime
ttlFrom: .metadata.annotations.ttlWith this configuration, the TTL for jobs will be taken from the ttl annotation. A job whose ttl annotation is set to 15s will be deleted 15 seconds after it completes.
Please refer to the examples folder for more usage patterns.
A detailed API reference can be found on the API docs page.