The Kubernetes controller Cleaner identifies, removes, or updates stale/orphaned or unhealthy resources to maintain a clean and efficient Kubernetes cluster. It is designed to handle any Kubernetes resource types (including your own custom resources) and provides sophisticated filtering capabilities, including label-based selection and custom Lua-based criteria. Cleaner can also be used to identify unhealthy resources.
k8s-cleaner keeps you in the loop with handy notifications through:
Each notification contains list of all resources successfully deleted (or modified) by k8s-cleaner. Choose what works best for you!
Currently k8s-cleaner has rich set of working examples to identify and list unused:
- ConfigMaps/Secrets
- ClusterRoles/Roles
- ServiceAccounts
- PersistentVolumes/PersistentVolumeClaims
- Deployments/StatefulSets
- Identify resources based on annotation indicating the maximum lifespan or the expiration date
- More
There are also examples to identify unhealthy resources:
- Pods Mounting Secrets with Old Content: Detect pods that are not utilizing the most recent Secret data.
- Pods Using Expired Certificates: Pinpoint pods that are operating with expired security certificates.
1️⃣ Schedule: Specify the frequency at which the k8s-cleaner should scan the cluster and identify stale resources. Utilise the Cron syntax to define recurring schedules.
2️⃣ DryRun: Enable safe testing of the k8s-cleaner filtering logic without affecting actual resource configurations. Resources matching the criteria will get identified, but no changes will get applied.
3️⃣ Label Filtering: Select resources based on user-defined labels, filtering out unwanted or outdated components. Refine the selection based on label key, operation (equal, different, etc.), and value.
4️⃣ Lua-based Selection Criteria: Leverage the Lua scripting language to create complex and dynamic selection criteria, catering to specific resource management needs. Define custom logic to identify and handle stale resources. To validate the Cleaner configuration, have a look here.
5️⃣ Notifications: Stay informed! The k8s-cleaner keeps users in the loop about every cleaned-up resource, whether removed or optimized. Get detailed notification lists and pick your preferred channel: Slack, Webex, Discord, Teams, SMTP or reports.
For a complete list of features with examples, have a look at the link.
💪 Resource Removal: Efficiently remove stale resources from your cluster, reclaiming unused resources and improving resource utilisation.
💪 Resource Updates: Update outdated resources to ensure they align with the latest configurations and maintain consistent functionality.
💪 Reduced Resource Bloat: Minimize resource bloat and maintain a clean and organized cluster, improving overall performance and stability.
By combining the flexibility of scheduling, the accuracy of label filtering, the power of Lua-based criteria, and the ability to remove or update stale resources, the k8s-cleaner empowers users to effectively manage Kubernetes environments and optimise resource usage.
- 👉 For feature requests and bugs, file an issue.
- 👉 To get updates ⭐️ star this repository.
- 👉 Working examples can be found in the examples section.
If you manage a fleet of Kubernetes clusters, Sveltos simplifies the deployment and management of k8s-cleaner across your entire infrastructure. Instead of manually deploying k8s-cleaner to each cluster, Sveltos offers a centralized platform to:
- Automate Deployment: Easily deploy k8s-cleaner to multiple clusters with a single configuration.
- Manage Configurations: Centrally manage k8s-cleaner configurations and apply them consistently across all clusters.
- Ensure Consistency: Maintain consistent k8s-cleaner configurations and versions across your fleet.
Detailed information can be found here.
To verify the correctness of the Cleaner configuration, follow the comprehensive instructions provided in the documentation: here and here.
In essence, the Cleaner YAML file alongside the YAML files representing matching and non-matching resources need to get provided, and then by executing the simple make ut
command the resutls will appear. This will validate whether your configuration correctly identifies and manages the desired resources.
We encourage everyone to contribute to the example directory by adding new Cleaner configurations 💡. This will help the community benefit from different expertise and build a stronger knowledge base of the Cleaner use cases.
To add an example, simply create a new file in the example directory with a descriptive name and put your Cleaner configuration within the file. Once you've added your example, feel free to submit a pull request to share it with the community.
🤝 Together we can expand the range of Cleaner applications and make it an even more valuable tool for managing Kubernetes resources efficiently.
This project adheres to the CNCF Code of Conduct
By participating, you are expected to honor this code.
Gianluca Mardente 💻 |
Oliver Bähler 💻 |
Eleni Grosdouli 📖 |
Colin J Lacy 💻 |
Amin Mohammadian 📖 |