{"id":13775258,"url":"https://github.com/gianlucam76/k8s-cleaner","last_synced_at":"2025-05-05T18:47:20.803Z","repository":{"id":211470308,"uuid":"728189395","full_name":"gianlucam76/k8s-cleaner","owner":"gianlucam76","description":"Cleaner is a Kubernetes controller that identifies unused or unhealthy resources, helping you maintain a streamlined and efficient Kubernetes cluster. It provides flexible scheduling, label filtering, Lua-based selection criteria, resource removal or update and notifications via Slack, Webex and Discord. it can also automate clusters operations.","archived":false,"fork":false,"pushed_at":"2025-05-05T15:38:14.000Z","size":6966,"stargazers_count":467,"open_issues_count":10,"forks_count":31,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-05T16:49:36.387Z","etag":null,"topics":["discord","kubernetes","kubernetes-operator","lua","notifications","orphaned-resources","slack","stale-resources","unused-resources","webex"],"latest_commit_sha":null,"homepage":"https://projectsveltos.github.io/sveltos/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gianlucam76.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"gianlucam76"}},"created_at":"2023-12-06T12:22:28.000Z","updated_at":"2025-05-05T15:38:01.000Z","dependencies_parsed_at":"2024-02-16T11:38:17.759Z","dependency_job_id":"344a416c-65b5-4c8b-a8e2-4a6184adfe3f","html_url":"https://github.com/gianlucam76/k8s-cleaner","commit_stats":null,"previous_names":["gianlucam76/k8s-pruner","gianlucam76/k8s-cleaner"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gianlucam76%2Fk8s-cleaner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gianlucam76%2Fk8s-cleaner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gianlucam76%2Fk8s-cleaner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gianlucam76%2Fk8s-cleaner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gianlucam76","download_url":"https://codeload.github.com/gianlucam76/k8s-cleaner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252555995,"owners_count":21767272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","kubernetes","kubernetes-operator","lua","notifications","orphaned-resources","slack","stale-resources","unused-resources","webex"],"created_at":"2024-08-03T17:01:35.981Z","updated_at":"2025-05-05T18:47:20.783Z","avatar_url":"https://github.com/gianlucam76.png","language":"Go","funding_links":["https://github.com/sponsors/gianlucam76"],"categories":["Tools and Libraries","Go","lua"],"sub_categories":["Miscellaneous"],"readme":"\n[![CI](https://github.com/gianlucam76/k8s-cleaner/actions/workflows/main.yaml/badge.svg)](https://github.com/gianlucam76/k8s-cleaner/actions)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gianlucam76/k8s-cleaner)](https://goreportcard.com/report/github.com/gianlucam76/k8s-cleaner)\n[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/gianlucam76/k8s-cleaner/badge)](https://scorecard.dev/viewer/?uri=github.com/gianlucam76/k8s-cleaner)\n[![Docker Pulls](https://img.shields.io/docker/pulls/projectsveltos/k8s-cleaner.svg)](https://store.docker.com/community/images/projectsveltos/k8s-cleaner)\n[![Slack](https://img.shields.io/badge/join%20slack-%23projectsveltos-brighteen)](https://join.slack.com/t/projectsveltos/shared_invite/zt-1hraownbr-W8NTs6LTimxLPB8Erj8Q6Q)\n[![License](https://img.shields.io/badge/license-Apache-blue.svg)](LICENSE)\n[![Twitter Follow](https://img.shields.io/twitter/follow/projectsveltos?style=social)](https://twitter.com/projectsveltos)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/gianlucam76/k8s-cleaner/main/assets/logo.png\" width=\"200\"\u003e\n\nThe 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.\n__Cleaner__ can also be used to identify unhealthy resources.\n\nk8s-cleaner keeps you in the loop with handy notifications through:\n\n1. \u003cimg src=\"assets/slack_logo.png\" alt=\"Slack\" width=\"30\" /\u003e  [__Slack__](https://gianlucam76.github.io/k8s-cleaner/notifications/notifications/#slack-notifications-example)\n1. \u003cimg src=\"assets/webex_logo.png\" alt=\"Webex\" width=\"30\" /\u003e  [__Webex__](https://gianlucam76.github.io/k8s-cleaner/notifications/notifications/#webex-notifications-example)\n1. \u003cimg src=\"assets/discord_logo.png\" alt=\"Discord\" width=\"30\" /\u003e  [__Discord__](https://gianlucam76.github.io/k8s-cleaner/notifications/notifications/#discord-notifications-example)\n1. \u003cimg src=\"assets/teams_logo.svg\" alt=\"Teams\" width=\"30\" /\u003e  [__Teams__](https://gianlucam76.github.io/k8s-cleaner/notifications/notifications/#teams-notifications-example)\n1. \u003cimg src=\"assets/telegram_logo.png\" alt=\"Telegram\" width=\"30\" /\u003e  [__Telegram__](https://gianlucam76.github.io/k8s-cleaner/notifications/notifications/#telegram-notifications-example)\n1. \u003cimg src=\"assets/smtp_logo.png\" alt=\"SMTP\" width=\"30\" /\u003e  [__SMTP__](https://gianlucam76.github.io/k8s-cleaner/notifications/notifications/#smtp-notifications-example)\n1.  [__reports__](https://gianlucam76.github.io/k8s-cleaner/reports/k8s-cleaner_reports/)\n  \nEach notification contains list of all resources successfully deleted (or modified) by k8s-cleaner. Choose what works best for you!\n\nCurrently k8s-cleaner has rich set of working examples to **identify** and **list** **unused**:\n\n- [ConfigMaps](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/configmaps)/[Secrets](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/secrets)\n- [ClusterRoles](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/clusterroles)/[Roles](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/roles)\n- [ServiceAccounts](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/service-accounts)\n- [PersistentVolumes](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/persistent-volumes)/[PersistentVolumeClaims](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/persistent-volume-claims)\n- [Deployments](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/deployments)/[StatefulSets](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/stateful-sets)\n- [Identify resources based on annotation indicating the maximum lifespan or the expiration date](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources/time_based_delete)\n- More\n\nThere are also examples to identify unhealthy resources:\n\n  - [Pods Mounting Secrets with Old Content](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unhealthy-resources/pod-with-outdated-secrets): Detect pods that are not utilizing the most recent Secret data.\n  - [Pods Using Expired Certificates](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unhealthy-resources/pod-with-expired-certificates): Pinpoint pods that are operating with expired security certificates.\n\n![k8s-cleaner in action](docs/assets/sveltos_roomba.gif)\n\n## Features and Capabilities\n\n1️⃣ [**Schedule**](https://gianlucam76.github.io/k8s-cleaner/getting_started/features/schedule/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.\n\n2️⃣ [**DryRun**](https://gianlucam76.github.io/k8s-cleaner/getting_started/features/dryrun/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.\n\n3️⃣ [**Label Filtering**](https://gianlucam76.github.io/k8s-cleaner/getting_started/features/label_filters/label_filters/): 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.\n\n4️⃣ **Lua-based Selection Criteria**: Leverage the [Lua](https://lua.org/) 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](#validate-the-cleaner-configuration).\n\n5️⃣ [**Notifications**](https://gianlucam76.github.io/k8s-cleaner/notifications/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, Telegram, SMTP or reports.\n\nFor a complete list of **features** with **examples**, have a look at the [link](https://gianlucam76.github.io/k8s-cleaner/getting_started/features/dryrun/dryrun/).\n\n## Benefits\n\n💪 **Resource Removal**: Efficiently remove stale resources from your cluster, reclaiming unused resources and improving resource utilisation.\n\n💪 **Resource Updates**: Update outdated resources to ensure they align with the latest configurations and maintain consistent functionality.\n\n💪 **Reduced Resource Bloat**: Minimize resource bloat and maintain a clean and organized cluster, improving overall performance and stability.\n\nBy 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.\n\n## How to work with us\n\n- 👉 For feature requests and bugs, file an [issue](https://github.com/gianlucam76/k8s-cleaner/issues).\n- 👉 To get updates [⭐️ star](https://github.com/gianlucam76/k8s-cleaner/stargazers) this repository.\n- 👉 Working examples can be found in the [examples](https://github.com/gianlucam76/k8s-cleaner/tree/main/examples-unused-resources) section.\n\n## Getting Started Guide\n\n- ✅  [Install](https://gianlucam76.github.io/k8s-cleaner/getting_started/install/install/) \n- 📖  [Complete Documentation](http://k8scleaner.projectsveltos.io/)\n\n## Install on Multiple Clusters with Sveltos\n\nIf you manage a fleet of Kubernetes clusters, [Sveltos](https://github.com/projectsveltos) 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:\n\n- **Automate Deployment**: Easily deploy k8s-cleaner to multiple clusters with a single configuration.\n- **Manage Configurations**: Centrally manage k8s-cleaner configurations and apply them consistently across all clusters.\n- **Ensure Consistency**: Maintain consistent k8s-cleaner configurations and versions across your fleet.\n\nDetailed information can be found [here](https://gianlucam76.github.io/k8s-cleaner/getting_started/install/install_on_multiple_cluster/).\n\n## Validate Cleaner Configuration \n\nTo verify the correctness of the __Cleaner__ configuration, follow the comprehensive instructions provided in the documentation: [here](https://github.com/gianlucam76/k8s-cleaner/blob/main/internal/controller/executor/validate_transform/README.md) and [here](https://github.com/gianlucam76/k8s-cleaner/blob/main/internal/controller/executor/validate_transform/README.md).\n\nIn 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.\n\n## Contribute\n\nWe 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.\n\nTo 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.\n\n🤝 Together we can expand the range of Cleaner applications and make it an even more valuable tool for managing Kubernetes resources efficiently.\n\n## Code of Conduct\n\nThis project adheres to the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md)\n\nBy participating, you are expected to honor this code.\n\n## Contributors\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://projectsveltos.github.io/sveltos/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/52940363?v=4?s=100\" width=\"100px;\" alt=\"Gianluca Mardente\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGianluca Mardente\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gianlucam76/k8s-cleaner/commits?author=gianlucam76\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://keybase.io/oliverbaehler\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/26610571?v=4?s=100\" width=\"100px;\" alt=\"Oliver Bähler\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eOliver Bähler\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gianlucam76/k8s-cleaner/commits?author=oliverbaehler\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/egrosdou01\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/147995681?v=4?s=100\" width=\"100px;\" alt=\"Eleni Grosdouli\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eEleni Grosdouli\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gianlucam76/k8s-cleaner/commits?author=egrosdou01\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/colinjlacy\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4993605?v=4?s=100\" width=\"100px;\" alt=\"Colin J Lacy\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eColin J Lacy\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gianlucam76/k8s-cleaner/commits?author=colinjlacy\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/aminmr\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/61911987?v=4?s=100\" width=\"100px;\" alt=\"Amin Mohammadian\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAmin Mohammadian\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gianlucam76/k8s-cleaner/commits?author=aminmr\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgianlucam76%2Fk8s-cleaner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgianlucam76%2Fk8s-cleaner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgianlucam76%2Fk8s-cleaner/lists"}