Skip to main content

A CLI tool for cleaning up Kubernetes pods 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.0.tar.gz (10.4 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.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: podr-0.1.0.tar.gz
  • Upload date:
  • Size: 10.4 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.0.tar.gz
Algorithm Hash digest
SHA256 958869cb6129d942edc9210876ac26e0c13fb1c3c2728871da284cb236a8ae3e
MD5 5b5de0fbef3324e81e11880cb075c6de
BLAKE2b-256 2a8f73339bcc376b4cc4f45e3b8efac954fe7230e11e089ffd3ade92f6d8d78a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: podr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6040f387d03c6607bddafca3b1edccee3fd88856d74596ec8e4236b397f24dee
MD5 07af0e131f57bb1b3622c91ff6abf92b
BLAKE2b-256 f5bdc4a78bdbf6f5f08f68092c626dd305302b815394806c880a9e1f4c3416a1

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