How to automatically clean up failed Kubernetes Pod every 24 hours.
A Micro-Blog around how to cleanup failed workloads which are stuck in failed states automatically for more than 24 hours.
Why Clean up in the first place?
There are often edge cases around when we to have cronjobs / pods / workloads which aren’t mission critical and often failed which might cause and issue around when we want list and navigate between the number of existing pods or if your Kubenetes Cluster is hosted under spot-instances from major cloud providers on which the underlying nodes get evicted causing the failed workloads around them sometime to be present for much longer than expected.
CleanUp Script.
This script is a Kubernetes cronjob which automatically deletes all the pods which are in failed state for more than an 24 hours.
“If you found this article useful, feel free to 👏 clap many times or share it with your friends. If you have any doubts regarding the same or anything around the DevOps Space, get in touch with me on Linkedin, Twitter, Instagram.”