zen-gc is a Kubernetes controller that automates garbage collection for various Kubernetes resources based on user-defined time-to-live (TTL) policies. With powerful options and zero configuration complexity, zen-gc ensures efficient, declarative cleanup without manual scripts, making resource management both easy and reliable.
zen-gc is an innovative Kubernetes controller designed to provide automatic, declarative garbage collection for a variety of Kubernetes resources based on time-to-live (TTL) policies. This means once cleanup policies are defined, zen-gc takes care of the rest, removing the need for custom controllers or manual cleanup scripts.
Kubernetes natively supports TTL only for Jobs, leaving users to manage cleanup for other resources like ConfigMaps, Secrets, Pods, and Custom Resource Definitions (CRDs) on their own. zen-gc addresses this limitation by offering a straightforward and Kubernetes-native solution that streamlines the cleanup process.
The versatility of zen-gc is predominantly showcased in its robust TTL management, which features four distinct modes:
Fixed TTL: A straightforward approach for time-based cleanup. For instance, resources can be deleted after a set period:
ttl:
secondsAfterCreation: 604800 # 7 days
Field-Based TTL: This mode allows resources to determine their own lifespan based on specific fields:
ttl:
fieldPath: "spec.ttlSeconds" # Resource controls its own TTL
Mapped TTL: Define timeframes based on resource attributes—ideal for severity-based retention policies:
ttl:
fieldPath: "spec.severity"
mappings:
CRITICAL: 1814400 # 3 weeks
HIGH: 1209600 # 2 weeks
MEDIUM: 604800 # 1 week
LOW: 259200 # 3 days
default: 604800
Relative TTL: Configures cleanup times relative to another resource's timestamp:
ttl:
relativeTo: "status.lastProcessedAt"
secondsAfter: 86400 # 1 day after last activity
This flexible architecture allows zen-gc to mold its functionality to the diverse requirements of different use cases.
While installation instructions are not included here, users can easily install zen-gc and create cleanup policies through Helm or kubectl. For example, a policy to cleanup temporary ConfigMaps after an hour could look like this:
apiVersion: gc.kube-zen.io/v1alpha1
kind: GarbageCollectionPolicy
metadata:
name: cleanup-temp-configmaps
spec:
targetResource:
apiVersion: v1
kind: ConfigMap
labelSelector:
matchLabels:
temporary: "true"
ttl:
secondsAfterCreation: 3600 # 1 hour
behavior:
maxDeletionsPerSecond: 10
zen-gc can be applied across a wide array of scenarios including:
Comprehensive documentation is available, including:
With its versatile features and user-friendly design, zen-gc stands as a production-ready solution highly suitable for Kubernetes operators seeking to enhance resource management and automation.
No comments yet.
Sign in to be the first to comment.