Open shift clean up pods with completed status

2/24/2022

We clean up pods with completed status manually. Is there a way to automate cleaning up pods that have completed status?

-- Vaishu13
kubernetes
openshift

1 Answer

2/25/2022

Extending Yuwei's answer:

There is no built-in option to automate such "garbage collection", that's why there is a workaround to make a simple script of kubectl command by using timeout command. Here you can find the article on How to use Timeout command.

So it will be something like this:

timeout -s9 300m kubectl delete pod --field-selector status.phase=Succeeded -A

or

timeout -s9 300m kubectl delete job <job-name>
-- Bazhikov
Source: StackOverflow