Automatically iterates through resources in a lab Kubernetes cluster and acts according to certain conditions outlined here. As of now, Kubesweeper will delete Deployments
and their associated resources if the waiting reason and/or pod restart count and/or deployment age dictates. Additionally, you can use configurable Boolean environment variables to choose to delete associated Services
, Ingresses
, and HorizontalPodAutoscalers
.
If your lab Kubernetes clusters are filling up with non-Running pods, then Kubesweeper's automatic deletion can assist. Future iterations of this project can involve other actions based on crawling through Kubernetes cluster resources, such as generating reports per namespace without actually deleting.
Please note that Kubesweeper is intended for use in lab—not production, customer-facing—clusters. Any automated cleanup in such an environment is unadvisable, at least for Kubesweeper.
If the desired cluster does not have Knative installed, then Kubesweeper can be installed as a Kubernetes CronJob.
- Build Docker image
$ docker build -t kubesweeper .
- Create Kubernetes resources from
install
directory
$ kubectl apply -f install/
Note that step 2 must be run in the context of the Kubernetes cluster. After that command is run, the appropriate Kubernetes resources will be created from the .yaml files in install
.
If you wish to deploy Kubesweeper on Knative as a CronJobSource, you can use Helm. For information on installing Helm, please refer to the Helm quickstart guide. After installing Helm, the following steps can be manually run:
- Build Docker image
$ docker build -t kubesweeper .
- Run Helm template to install Kubesweeper
$ helm template kubesweeper --set image=<KUBESWEEPER_IMAGE> | kubectl create -f -
In lieu of step 2, a Makefile can be used to pull values from ~/install/helm/kubesweeper/values.yaml
:
$ make
Under the configs
folder, the config.yaml
has the following default configurations:
- Pod waiting reasons
- CrashLoopBackOff
- ImagePullBackOff
- ErrImagePull
- Completed
- Failed
- Pod restart threshold (in other words, if pod restarts exceed this number, then delete)
- 100
- If the pod restart threshold is at least this number and has a pod waiting reason of
CrashLoopBackOff
, then Kubesweeper will delete the associated resources
- If the pod restart threshold is at least this number and has a pod waiting reason of
- 100
- Deployment age threshold (in other words, if the deployment creation date is before this number of days, then delete)
- 90
You are able to configure these values to your choosing.
Helm function configurations can be found in ~/install/helm/kubesweeper/values.yaml
.
- name
- Name to use for deployment
- image
- Image used in deployment
- cron
- Cron expression used to schedule Kubesweeper
- Any valid cron expression can be used
- Cron expression used to schedule Kubesweeper
- namespace
- Namespace job will be deployed in
- Fork Kubesweeper
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
Maintained and in-use by the Platform Team @ AT&T Entertainment Cloud Native Labs.
Distributed under the AT&T MIT license. See LICENSE
for more information.