https://github.com/att-cloudnative-labs/kubesweeper
Removes unnecessary Kubernetes resources based on a configurable pod restart threshold.
https://github.com/att-cloudnative-labs/kubesweeper
docker go golang helm knative kubernetes
Last synced: 6 months ago
JSON representation
Removes unnecessary Kubernetes resources based on a configurable pod restart threshold.
- Host: GitHub
- URL: https://github.com/att-cloudnative-labs/kubesweeper
- Owner: att-cloudnative-labs
- License: mit
- Created: 2019-03-28T22:32:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-09T18:18:32.000Z (over 6 years ago)
- Last Synced: 2025-04-09T21:40:26.265Z (about 1 year ago)
- Topics: docker, go, golang, helm, knative, kubernetes
- Language: Go
- Homepage:
- Size: 153 KB
- Stars: 19
- Watchers: 4
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kubesweeper
Automatically iterates through resources in a lab Kubernetes cluster and acts according to [certain conditions outlined here](#configuration-defaults). 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.
## Deployment as a Kubernetes CronJob
If the desired cluster does not have Knative installed, then Kubesweeper can be installed as a Kubernetes CronJob.
1. Build Docker image
```bash
$ docker build -t kubesweeper .
```
2. Create Kubernetes resources from ```install``` directory
```bash
$ 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```.
## Deployment as a Knative CronJobSource
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](https://helm.sh/docs/using_helm/). After installing Helm, the following steps can be manually run:
1. Build Docker image
```bash
$ docker build -t kubesweeper .
```
2. Run Helm template to install Kubesweeper
```bash
$ helm template kubesweeper --set image= | kubectl create -f -
```
In lieu of step 2, a Makefile can be used to pull values from ```~/install/helm/kubesweeper/values.yaml```:
```bash
$ make
```
## Configuration Defaults
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
* 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
* namespace
* Namespace job will be deployed in
## Contributing
1. [Fork Kubesweeper](https://github.com/att-cloudnative-labs/kubesweeper/fork)
2. Create your feature branch (`git checkout -b feature/fooBar`)
3. Commit your changes (`git commit -am 'Add some fooBar'`)
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request
## Additional info
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.