Tired of lingering Kubernetes pods and jobs cluttering your namespaces? Meet Pod Reaper, the ultimate cleanup tool for your cluster.
podr is a simple but powerful CLI tool that finds Kubernetes pods and jobs in a specific state (like Succeeded, Failed, or Error) and deletes them. Stop manually running kubectl delete and automate your cluster hygiene!
In a dynamic Kubernetes environment, completed pods (Succeeded) and failed jobs (Failed) can accumulate quickly. This digital debris clutters your cluster, making it difficult to monitor and manage. While a few leftover resources might seem harmless, they can eventually:
- Obscure real issues: A long list of failed pods makes it hard to spot new, critical failures.
- Consume resources: In some cases, completed resources can still hold on to claims or other resources.
- Create noise: A messy
kubectl get podsoutput is a daily annoyance for any developer or SRE.
- 🎯 Simple & Specific: Target exactly what you want to delete. Clean up
Succeededpods,Failedjobs, or pods in anErrorstate with a single, readable command. - 🤖 Automation-Ready: Generate Kubernetes
CronJobYAML directly from the CLI. Set up a GitOps workflow to keep your cluster clean automatically. - 🛡️ Safe & Predictable: Use the
--dry-runflag to see whatpodrwould delete before making any changes. No surprises. - 🌐 Namespace Flexible: Clean the current namespace, a specific namespace, or all namespaces at once (
-A).
Install directly from PyPI:
pip install podrThe command structure is simple: podr <resource> <state> [options]
| Resource | Supported States |
|---|---|
pods |
Succeeded, Failed, Error, Running, Pending |
jobs |
Completed, Failed, Active |
Examples:
# See which 'Succeeded' pods would be deleted in the 'default' namespace
podr pods Succeeded -n default --dry-run
# Delete all pods in an 'Error' state across the entire cluster
podr pods Error -A
# Delete all 'Completed' jobs in the current namespace
podr jobs Completed
# Generate a CronJob YAML to clean failed jobs every 15 minutes
podr jobs Failed --interval 900 --outputpodr comes with a full pytest suite and a script to generate test resources in your cluster.
To test podr in a real environment (like minikube), you can generate a sample set of pods and jobs.
-
Target your cluster: Make sure your
kubectlcontext is pointing to the desired test cluster. -
Run the script:
python3 generate_test_resources.py
This will create a new namespace pod-reaper-test and populate it with resources in various states, ready for reaping.
Run the full pytest suite locally:
make testWe welcome contributions! Whether it's a bug fix, a new feature, or a documentation improvement, we'd love your help.
- Fork the repository.
- Create a new branch:
git checkout -b my-feature-branch - Set up your development environment:
make install-dev
- Make your changes.
- Run the tests:
make test - Submit a pull request!
We'll review your PR as soon as possible.
This project is licensed under the MIT License. See the LICENSE file for details.