Skip to main content

A CLI tool for cleaning up Kubernetes resources in specific states

Project description

Pod Reaper (podr) 💀

Pytest License: MIT GitHub stars

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!


The Problem: A Messy Cluster

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 pods output is a daily annoyance for any developer or SRE.

Why Pod Reaper?

  • 🎯 Simple & Specific: Target exactly what you want to delete. Clean up Succeeded pods, Failed jobs, or pods in an Error state with a single, readable command.
  • 🤖 Automation-Ready: Generate Kubernetes CronJob YAML directly from the CLI. Set up a GitOps workflow to keep your cluster clean automatically.
  • 🛡️ Safe & Predictable: Use the --dry-run flag to see what podr would delete before making any changes. No surprises.
  • 🌐 Namespace Flexible: Clean the current namespace, a specific namespace, or all namespaces at once (-A).

🚀 Installation

Install directly from PyPI:

pip install podr

Usage

The 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 --output

🧪 Development & Testing

podr comes with a full pytest suite and a script to generate test resources in your cluster.

Generating Test Resources

To test podr in a real environment (like minikube), you can generate a sample set of pods and jobs.

  1. Target your cluster: Make sure your kubectl context is pointing to the desired test cluster.

  2. 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.

Running the Test Suite

Run the full pytest suite locally:

make test

🙌 How to Contribute

We welcome contributions! Whether it's a bug fix, a new feature, or a documentation improvement, we'd love your help.

  1. Fork the repository.
  2. Create a new branch: git checkout -b my-feature-branch
  3. Set up your development environment:
    make install-dev
    
  4. Make your changes.
  5. Run the tests: make test
  6. Submit a pull request!

We'll review your PR as soon as possible.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

podr-0.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

podr-0.1.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file podr-0.1.1.tar.gz.

File metadata

  • Download URL: podr-0.1.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for podr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6543b4deb4648e550d4c9fb225d409349ef8bd10450d6a6e39b334cd5b382451
MD5 86e6b6e6c194b36b784f1085b47dd8ce
BLAKE2b-256 35d064eb4cac2478bf5075a07f6fe94d422e24fb43e7bf6fcf4da3a2186fb36c

See more details on using hashes here.

File details

Details for the file podr-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: podr-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for podr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40fb42ae1ac9f771a6b95586ec3b19b02f51aa1639dea9e23a0933aff0ee4fa2
MD5 4c1345811ba56f86e0fe253d903ce6c4
BLAKE2b-256 f6744fdaae3a0eb70daf427d36fab99939abca9a6d72bb7682019b4aa20dc920

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page