Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Kubernetes Operator to automatically delete completed Jobs and their Pods

License

Notifications You must be signed in to change notification settings

gravitational/kube-cleanup-operator

 
 

Repository files navigation

Kubernetes cleanup operator

Build Status Go Report Card Docker Repository on Quay

Experimental Kubernetes Operator to automatically delete completed Jobs and their Pods. Controller listens for changes in Pods created by Jobs and deletes it on Completion.

Some defaults:

  • All Namespaces are monitored by default
  • Only Pods created by Jobs are monitored

Usage

screensharing

# remember to change namespace in RBAC manifests for monitoring namespaces other than "default"

kubectl create -f https://raw.githubusercontent.com/lwolf/kube-cleanup-operator/master/deploy/rbac.yaml

# create deployment
kubectl create -f https://raw.githubusercontent.com/lwolf/kube-cleanup-operator/master/deploy/deployment.yaml


kubectl logs -f $(kubectl get pods --namespace default -l "run=cleanup-operator" -o jsonpath="{.items[0].metadata.name}")

# Use simple job to test it
kubectl create -f https://k8s.io/examples/controllers/job.yaml

Docker images

docker pull quay.io/gravitational/kube-cleanup-operator

or you can build it yourself as follows:

$ make install_deps
$ make build
$ cp bin/kube-cleanup-operator .
$ docker build .

Development

$ make install_deps
$ make build
$ ./bin/kube-cleanup-operator --help
Usage of ./bin/kube-cleanup-operator:
  -namespace string
    	Watch only this namespaces (omit to operate clusterwide)
  -run-outside-cluster
    	Set this flag when running outside of the cluster.
  -keep-successful
        the number of hours to keep a succesfull job
        -1 - forever 
        0  - never (default)
        >0 - number of hours
  -keep-failures
        the number of hours to keep a failed job
        -1 - forever (default)
        0  - never
        >0 - number of hours
  -keep-pending
        the number of hours to keep a pending job
        -1 - forever (default)
        0  - forever
        >0 - number of hours
  -dry-run
        Perform dry run, print only
        
$ ./bin/kube-cleanup-operator --run-outside-cluster --namespace=default --keep-successful=0 --keep-failures=-1 --keep-pending=-1

About

Kubernetes Operator to automatically delete completed Jobs and their Pods

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 83.4%
  • Makefile 14.5%
  • Dockerfile 2.1%