Skip to content

Kubernetes controller for automated resource cleanup using TTL annotations. Efficiently manage resource lifecycles in your K8s clusters.

Notifications You must be signed in to change notification settings

abhinavgrover15/resource-reaper

Repository files navigation

Resource Reaper

GitHub release (latest by date) CI Helm Release codecov Go Report Card License: MIT Docker Image Size

Resource Reaper is a Kubernetes controller that automatically manages resource lifecycles using TTL (Time-To-Live) annotations. It helps maintain cluster hygiene by automatically cleaning up resources that have exceeded their specified lifetime.

🌟 Features

  • TTL-based Cleanup: Automatically delete resources when they exceed their time-to-live
  • Flexible Annotations: Use simple annotations to specify resource lifetimes
  • Multiple Resource Support: Works with various Kubernetes resources (Pods, Deployments, etc.)
  • Leader Election: Supports high availability deployments
  • Metrics: Prometheus metrics for monitoring cleanup operations
  • Helm Installation: Easy deployment using Helm chart
  • Resource Efficient: Minimal resource footprint
  • Kubernetes Native: Built using controller-runtime framework

🚀 Quick Start

Install using Helm:

helm repo add resource-reaper https://abhinavgrover15.github.io/resource-reaper
helm repo update
helm install resource-reaper resource-reaper/resource-reaper

Add TTL annotation to your resources:

annotations:
  reaper.resource/ttl: "24h"  # Resource will be deleted after 24 hours

Overview

Resource Reaper watches Kubernetes resources and automatically deletes them when their TTL expires. This is useful for:

  • Cleaning up temporary resources
  • Managing development/test environments
  • Automatic cleanup of completed jobs
  • Time-limited demo resources

Supported Resources

  • Core Resources: Pods, Services, ConfigMaps, Secrets
  • Apps Resources: Deployments, StatefulSets, DaemonSets
  • Batch Resources: Jobs, CronJobs

Usage

Add the resource-reaper/ttl annotation to any supported resource:

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
  annotations:
    resource-reaper/ttl: "2h"  # Pod will be deleted after 2 hours
spec:
  containers:
  - name: nginx
    image: nginx:latest

Supported TTL formats:

  • Hours: "1h", "2h"
  • Minutes: "30m", "45m"
  • Days: "2d", "7d"
  • Immediate deletion: "0s"

Installation

Using kubectl

  1. Apply the RBAC configuration:
kubectl apply -f https://raw.githubusercontent.com/abhinavgrover15/resource-reaper/main/config/rbac.yaml
  1. Deploy the controller:
kubectl apply -f https://raw.githubusercontent.com/abhinavgrover15/resource-reaper/main/config/deployment.yaml

Using Helm

  1. Add the Helm repository:
helm repo add resource-reaper https://abhinavgrover15.github.io/resource-reaper
helm repo update
  1. Install the chart:
helm install resource-reaper resource-reaper/resource-reaper

Development

Building from source

  1. Clone the repository:
git clone https://github.com/abhinavgrover15/resource-reaper.git
cd resource-reaper
  1. Build the container:
docker build -t resource-reaper:latest .
  1. Deploy to Kubernetes:
kubectl apply -f config/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

About

Kubernetes controller for automated resource cleanup using TTL annotations. Efficiently manage resource lifecycles in your K8s clusters.

Topics

Resources

Stars

Watchers

Forks

Packages