You can enable TTL Controller (for k8s 1.12 and above), if it's not enabled already and, add ttlSecondsAfterFinished: N
parameter, in which case the pods, that created the job, and the job itself will be deleted after N seconds.
(如果尚未启用TTL控制器 (适用于k8s 1.12及更高版本),则可以启用它,并添加ttlSecondsAfterFinished: N
参数,在这种情况下,创建作业的ttlSecondsAfterFinished: N
和作业本身将在N秒后删除。)
For example:
(例如:)
apiVersion: batch/v1
kind: Job
metadata:
name: pi-with-ttl
spec:
ttlSecondsAfterFinished: 0
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
This typical kubernetes pi
job will clean itself up immediatly after getting to completed.
(完成后,此典型的kubernetes pi
工作将立即清理自身。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…