How do I automatically remove completed Kubernetes

2019-03-22 14:49发布

Is there a way to automatically remove completed jobs besides making a cronjob to clean up completed jobs?

The K8s Job Documentation states that the intended behavior of completed jobs is for them to remain in a completed state until manually deleted. Because I am running thousands of jobs a day via k8s cronjobs and I don't want to keep completed jobs around.

8条回答
老娘就宠你
2楼-- · 2019-03-22 15:15

You can now set history limits, or disable history altogether, so that failed or successful jobs are not kept around indefinitely. See my answer here. Documentation is here.

查看更多
Bombasti
3楼-- · 2019-03-22 15:16

This is possible from version 1.12 Alpha with ttlSecondsAfterFinished. An example from Clean Up Finished Jobs Automatically:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-ttl
spec:
  ttlSecondsAfterFinished: 100
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
查看更多
登录 后发表回答