{"id":13811690,"url":"https://github.com/micnncim/kubectl-reap","last_synced_at":"2026-01-12T02:58:11.245Z","repository":{"id":37983089,"uuid":"288123388","full_name":"micnncim/kubectl-reap","owner":"micnncim","description":"kubectl plugin that deletes unused Kubernetes resources","archived":false,"fork":false,"pushed_at":"2023-05-19T08:21:45.000Z","size":301,"stargazers_count":198,"open_issues_count":11,"forks_count":15,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-31T18:21:17.929Z","etag":null,"topics":["krew","kubectl","kubectl-plugin","kubernetes"],"latest_commit_sha":null,"homepage":"","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/micnncim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2020-08-17T08:20:01.000Z","updated_at":"2024-10-12T15:56:01.000Z","dependencies_parsed_at":"2024-01-15T14:23:50.005Z","dependency_job_id":null,"html_url":"https://github.com/micnncim/kubectl-reap","commit_stats":null,"previous_names":["micnncim/kubectl-prune"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micnncim%2Fkubectl-reap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micnncim%2Fkubectl-reap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micnncim%2Fkubectl-reap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micnncim%2Fkubectl-reap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micnncim","download_url":"https://codeload.github.com/micnncim/kubectl-reap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253150074,"owners_count":21861829,"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":["krew","kubectl","kubectl-plugin","kubernetes"],"created_at":"2024-08-04T04:00:28.902Z","updated_at":"2026-01-12T02:58:11.219Z","avatar_url":"https://github.com/micnncim.png","language":"Go","funding_links":[],"categories":["Kubernetes","kubernetes"],"sub_categories":["Kubernetes tools"],"readme":"# kubectl-reap\n\n[![actions-workflow-test][actions-workflow-test-badge]][actions-workflow-test]\n[![release][release-badge]][release]\n[![codecov][codecov-badge]][codecov]\n[![pkg.go.dev][pkg.go.dev-badge]][pkg.go.dev]\n[![license][license-badge]][license]\n\n`kubectl-reap` is a kubectl plugin that deletes unused Kubernetes resources.\n\n![screencast](/docs/assets/screencast.gif)\n\nSupported resources:\n\n|          Kind           |                         Condition                          |\n| ----------------------- | ---------------------------------------------------------- |\n| Pod                     | Not running                                                |\n| ConfigMap               | Not referenced by any Pods or ReplicaSet                   |\n| Secret                  | Not referenced by any Pods, ReplicaSet, or ServiceAccounts |\n| PersistentVolume        | Not satisfying any PersistentVolumeClaims                  |\n| PersistentVolumeClaim   | Not referenced by any Pods                                 |\n| Job                     | Completed                                                  |\n| PodDisruptionBudget     | Not targeting any Pods                                     |\n| HorizontalPodAutoscaler | Not targeting any resources                                |\n\nSince this plugin supports dry-run as described below, it also helps you to find resources you misconfigured or forgot to delete.\n\nBefore getting started, read [the caveats of using this plugin](#caveats).\n\n## Installation\n\nDownload precompiled binaries from [GitHub Releases](https://github.com/micnncim/kubectl-reap/releases).\n\n### Via [Krew](https://github.com/kubernetes-sigs/krew)\n\n```\n$ kubectl krew install reap\n```\n\n### Via Homebrew\n\n```\n$ brew tap micnncim/kubectl-reap https://github.com/micnncim/kubectl-reap\n$ brew install kubectl-reap\n```\n\n### Via Go\n\n```\n$ go get github.com/micnncim/kubectl-reap/cmd/kubectl-reap\n```\n\n## Examples\n\n### Pods\n\nIn this example, this plugin deletes all Pods whose status is not `Running`.\n\n```console\n$ kubectl get po\nNAME          READY   STATUS      RESTARTS   AGE\npod-running   1/1     Running     0          10s\npod-pending   0/1     Pending     0          20s\npod-failed    0/1     Failed      0          30s\npod-unknown   0/1     Unknown     0          40s\njob-kqpxc     0/1     Completed   0          50s\n\n$ kubectl reap po\npod/pod-pending deleted\npod/pod-failed deleted\npod/pod-unknown deleted\npod/job-kqpxc deleted\n```\n\n### ConfigMaps\n\nIn this example, this plugin deletes the unused ConfigMap `config-2`.\n\n```console\n$ kubectl get cm\nNAME       DATA   AGE\nconfig-1   1      0m15s\nconfig-2   1      0m10s\n\n$ cat \u003c\u003cEOF | kubectl apply -f -\napiVersion: v1\nkind: Pod\nmetadata:\n  name: nginx\nspec:\n  containers:\n  - name: nginx\n    image: nginx\n    volumeMounts:\n    - name: config-1-volume\n      mountPath: /var/config\n  volumes:\n  - name: config-1-volume\n    configMap:\n      name: config-1\nEOF\n\n$ kubectl reap cm\nconfigmap/config-2 deleted\n```\n\n### Interactive Mode\n\nYou can choose which resource you will delete one by one by interactive mode.\n\n```console\n$ kubectl reap cm --interactive # or '-i'\n? Are you sure to delete configmap/config-1? Yes\nconfigmap/config-1 deleted\n? Are you sure to delete configmap/config-2? No\n? Are you sure to delete configmap/config-3? Yes\nconfigmap/config-3 deleted\n```\n\n## Usage\n\n```console\n$ kubectl reap --help\n\nDelete unused resources. Supported resources:\n\n- Pods (whose status is not Running)\n- ConfigMaps (not used by any Pods)\n- Secrets (not used by any Pods or ServiceAccounts)\n- PersistentVolumes (not satisfying any PersistentVolumeClaims)\n- PersistentVolumeClaims (not used by any Pods)\n- Jobs (completed)\n- PodDisruptionBudgets (not targeting any Pods)\n- HorizontalPodAutoscalers (not targeting any resources)\n\nUsage:\n  kubectl reap RESOURCE_TYPE [flags]\n\nExamples:\n\n  # Delete ConfigMaps not mounted on any Pods and in the current namespace and context\n  $ kubectl reap configmaps\n\n  # Delete unused ConfigMaps and Secrets in the namespace/my-namespace and context/my-context\n  $ kubectl reap cm,secret -n my-namespace --context my-context\n\n  # Delete ConfigMaps not mounted on any Pods and across all namespace\n  $ kubectl reap cm --all-namespaces\n\n  # Delete Pods whose status is not Running as client-side dry-run\n  $ kubectl reap po --dry-run=client\n\nFlags:\n  -A, --all-namespaces                 If true, delete the targeted resources across all namespace except kube-system\n      --allow-missing-template-keys    If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)\n      --as string                      Username to impersonate for the operation\n      --as-group stringArray           Group to impersonate for the operation, this flag can be repeated to specify multiple groups.\n      --cache-dir string               Default cache directory (default \"/Users/micnncim/.kube/cache\")\n      --certificate-authority string   Path to a cert file for the certificate authority\n      --client-certificate string      Path to a client certificate file for TLS\n      --client-key string              Path to a client key file for TLS\n      --cluster string                 The name of the kubeconfig cluster to use\n      --context string                 The name of the kubeconfig context to use\n      --dry-run string[=\"unchanged\"]   Must be \"none\", \"server\", or \"client\". If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource. (default \"none\")\n      --field-selector string          Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.\n      --force                          If true, immediately remove resources from API and bypass graceful deletion. Note that immediate deletion of some resources may result in inconsistency or data loss and requires confirmation.\n      --grace-period int               Period of time in seconds given to the resource to terminate gracefully. Ignored if negative. Set to 1 for immediate shutdown. Can only be set to 0 when --force is true (force deletion). (default -1)\n  -h, --help                           help for kubectl\n      --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure\n  -i, --interactive                    If true, a prompt asks whether resources can be deleted\n      --kubeconfig string              Path to the kubeconfig file to use for CLI requests.\n  -n, --namespace string               If present, the namespace scope for this CLI request\n  -o, --output string                  Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.\n  -q, --quiet                          If true, no output is produced\n      --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default \"0\")\n  -l, --selector string                Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)\n  -s, --server string                  The address and port of the Kubernetes API server\n      --template string                Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].\n      --timeout duration               The length of time to wait before giving up on a delete, zero means determine a timeout from the size of the object\n      --tls-server-name string         Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used\n      --token string                   Bearer token for authentication to the API server\n      --user string                    The name of the kubeconfig user to use\n  -v, --version                        If true, show the version of this plugin\n      --wait                           If true, wait for resources to be gone before returning. This waits for finalizers.\n\n```\n\n### Caveats\n\n- It's recommended to run this plugin as dry-run (`--dry-run=client` or `--dry-run=server`) first or interactive mode (`--interactive`) in order to examine what resources will be deleted when running it, especially when you're trying to run it in a production environment.\n- Even if you use `--namespace kube-system` or `--all-namespaces`, this plugin never deletes any resources in `kube-system` so that it prevents unexpected resource deletion.\n- This plugin doesn't determine whether custom controllers or CRDs consume or depend on the supported resources. Make sure the resources you want to reap aren't used by them.\n  - e.g.) A Secret which isn't used by any Pods or ServiceAccounts but used by [cert-manager](https://cert-manager.io) can be deleted\n\n## Background\n\n`kubectl apply --prune` allows us to delete unused resources.\nHowever, it's not very flexible when we want to choose what kind resource to be deleted.\nThis plugin provides more flexible, easy way to delete resources.\n\n## Similar Projects\n\n- [dtan4/k8s-unused-secret-detector](https://github.com/dtan4/k8s-unused-secret-detector)\n- [FikaWorks/kubectl-plugins/prune-unused](https://github.com/FikaWorks/kubectl-plugins/tree/master/prune-unused)\n- [dirathea/kubectl-unused-volumes](https://github.com/dirathea/kubectl-unused-volumes)\n\n\u003c!-- badge links --\u003e\n\n[actions-workflow-test]: https://github.com/micnncim/kubectl-reap/actions?query=workflow%3ATest\n[actions-workflow-test-badge]: https://img.shields.io/github/workflow/status/micnncim/kubectl-reap/Test?label=Test\u0026style=for-the-badge\u0026logo=github\n\n[release]: https://github.com/micnncim/kubectl-reap/releases\n[release-badge]: https://img.shields.io/github/v/release/micnncim/kubectl-reap?style=for-the-badge\u0026logo=github\n\n[codecov]: https://codecov.io/gh/micnncim/kubectl-reap\n[codecov-badge]: https://img.shields.io/codecov/c/github/micnncim/kubectl-reap?style=for-the-badge\u0026logo=codecov\n\n[pkg.go.dev]: https://pkg.go.dev/github.com/micnncim/kubectl-reap?tab=overview\n[pkg.go.dev-badge]: http://bit.ly/pkg-go-dev-badge\n\n[license]: LICENSE\n[license-badge]: https://img.shields.io/github/license/micnncim/kubectl-reap?style=for-the-badge\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicnncim%2Fkubectl-reap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicnncim%2Fkubectl-reap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicnncim%2Fkubectl-reap/lists"}