volcano.sh/volcano@v1.9.0/docs/user-guide/how_to_use_job_ttl.md (about) 1 # How to Configure Volcano Job Time to Live 2 ## Background 3 Similar to a standard `Job` resource, VolcanoJobs can be configured to be automatically garbage 4 collected after they finish execution (either Complete or Failed). This is configured by setting 5 `spec.ttlSecondsAfterFinished` which limits the lifetime of a Job. 6 7 ## Key Points 8 `ttlSecondsAfterFinished` is an optional parameter that can be configured on VolcanoJobs which 9 defaults to `nil`. The value of `ttlSecondsAfterFinished` must be a positive integer and indicates 10 the number of seconds after a job finishes executing (either Complete or Failed) before it becomes 11 eligible for garbage collection. 12 13 If `ttlSecondsAfterFinished` is unset or set to `nil`, the job will remain indefinitely. If set to 14 zero (`0`), the job will become eligible for garbage collection immediately upon completion. If set 15 to a positive integer, `N`, the job will become eligible for garbage collection `N` seconds after 16 the job has completed. 17 18 ## Other Reading 19 While this uses a custom garbage collector, this operates nearly identically to 20 `ttlSecondsAfterFinished` from a standard `batch.v1.job` resource. The [official Kubernetes 21 documentation](https://kubernetes.io/docs/concepts/workloads/controllers/ttlafterfinished/) has some 22 useful tips describing how mutating webhooks can be used to take greater advantage of 23 `ttlSecondsAfterFinished`. 24 25 ## Example 26 The manifest below creates a job that will be eligible for garbage collection 10 minutes after it 27 either completes or fails. 28 29 ```yaml 30 apiVersion: batch.volcano.sh/v1alpha1 31 kind: job 32 metadata: 33 generateName: test-job- 34 spec: 35 minAvailable: 1 36 schedulerName: volcano 37 queue: testing 38 ttlSecondsAfterFinished: 600 39 policies: 40 - event: PodEvicted 41 action: RestartJob 42 tasks: 43 - replicas: 1 44 name: sleeper 45 policies: 46 - event: TaskCompleted 47 action: CompleteJob 48 template: 49 spec: 50 restartPolicy: Never 51 imagePullPolicy: IfNotPresent 52 containers: 53 - name: sleeper 54 image: debian:buster 55 command: 56 - /bin/bash 57 - -c 58 - | 59 for i in {0..5}; do 60 echo "sleeping" 61 sleep 1 62 done 63 ```