https://github.com/mr-karan/k8s-pruner
Cleanup unused configmaps in a Kubernetes namespace
https://github.com/mr-karan/k8s-pruner
configmaps gitops kubernetes kustomize
Last synced: 3 months ago
JSON representation
Cleanup unused configmaps in a Kubernetes namespace
- Host: GitHub
- URL: https://github.com/mr-karan/k8s-pruner
- Owner: mr-karan
- License: mit
- Created: 2019-11-01T11:22:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-31T02:52:50.000Z (about 2 years ago)
- Last Synced: 2025-03-19T20:53:08.763Z (3 months ago)
- Topics: configmaps, gitops, kubernetes, kustomize
- Language: Shell
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# k8s-pruner
Cleanup unused Configmaps in a Kubernetes namespace## Why
For folks using Kustomize, the configmaps are prefixed with a random hash. Whenever you change the config, the hash is changed which signals the Deployment to rollout new Pods with new configmap and kill the old ones. The problem seems to be that the old ConfigMaps are not garbage collected and seems to be stored in the etcd cluster forever.
There is a [KEP](https://github.com/kubernetes/community/pull/2287) for garbage collection of unused resources but I've tested it with `1.14` cluster version and the issue still seems to persist.
## Features
- Runs inside Kubernetes cluster, no need to setup any external systems/bastions.
- Depends on K8s native RBAC and ServiceAccount for authentication/authorization.
- Executed as a CronJob## Deployment
- Checkout the manifests present at: `cd deployment/kubernetes/`
- `kubectl apply -f manifests/`By default, the CronJob is scheduled to run at 1AM every night, you can modify this according to your cluster configurations.
## Known Limitations
- If you've scaled down a deployment in a namespace, the configmaps will be deleted.
- If you want to rollback a deployment, with `kubectl rollout undo` this won't be possible (since the old configmap is deleted), however if you follow the `GitOps` way of deploying manifests, a simple `git revert` can help you.> NOTE: I am planning to port this shell script to a Golang binary with more bells and whistles and trying to overcome the above limitations, not recommended to use in Production as of yet.