Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jobs not deleting after completion with ttlSecondsAfterFinished

Tags:

kubernetes

I have a service that deploys thousands of short lived jobs on Kubernetes each day. I am trying to get Kubernetes to delete these jobs after completion using the functionality described here:

https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#clean-up-finished-jobs-automatically

The job completes, but the Job remains in the cluster after the time limit expressed in ttlSecondsAfterFinished.

I'm testing this on GKE and my master node is running 1.12.7-gke.25 I understand this is an alpha feature, but I haven't gotten a single Job to be deleted.

apiVersion: batch/v1 
kind: Job
metadata:
  name: ttl-test
spec:
  ttlSecondsAfterFinished: 100
  template:
    metadata:
      name: ttl-test 
    spec:
      containers:
      - name: test-container
        image: myimage
like image 608
Brett Avatar asked Oct 07 '19 12:10

Brett


People also ask

How do I delete all jobs from Kubernetes?

Delete the job with kubectl (e.g. kubectl delete jobs/pi or kubectl delete -f ./job. yaml ). When you delete the job using kubectl , all the pods it created are deleted too.

How do you configure a Kubernetes job so that pods are retained after completion?

How do you configure a Kubernetes Job so that Pods are retained after completion? - Configure the backofflimit parameter with a non-zero value. - Set a startingDeadlineSeconds value high enough to allow you to access the logs. - Set an activeDeadlineSeconds value high enough to allow you to access the logs.

How do I delete failed jobs on Kubernetes?

To delete failed Jobs in GKE you will need to use following command: $ kubectl delete job $(kubectl get job -o=jsonpath='{. items[?(@. status.

Do completed pods consume resources?

Nope, Kubernetes no more reserves memory or CPU once Pods are marked completed.


1 Answers

In Kubernetes v1.21 the TTL Controller is in beta and enabled by default.

Until Kubernetes v1.20 it was an alpha feature. If you want to use it with a Kubernetes version older than v1.21, make sure alpha features are enabled on your GKE cluster. You can check this on the GCP console UI under Clusters / <your_cluster> / Details / Kubernetes alpha features.

like image 99
gnvk Avatar answered Jan 03 '23 21:01

gnvk