百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
K

kubectl-reap

> 云原生
开源

一个 kubectl 插件,用于删除未使用的 Kubernetes 资源

199 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个 kubectl 插件,用于删除未使用的 Kubernetes 资源

kubectl-reap

actions-workflow-test release codecov pkg.go.dev license

kubectl-reap is a kubectl plugin that deletes unused Kubernetes resources.

Supported resources:

Kind Condition
Pod Not running
ConfigMap Not referenced by any Pods or ReplicaSet
Secret Not referenced by any Pods, ReplicaSet, or ServiceAccounts
PersistentVolume Not satisfying any PersistentVolumeClaims
PersistentVolumeClaim Not referenced by any Pods
Job Completed
PodDisruptionBudget Not targeting any Pods
HorizontalPodAutoscaler Not targeting any resources

Since this plugin supports dry-run as described below, it also helps you to find resources you misconfigured or forgot to delete.

Before getting started, read the caveats of using this plugin.

Installation

Download precompiled binaries from GitHub Releases.

Via Krew

$ kubectl krew install reap

Via Homebrew

$ brew tap micnncim/kubectl-reap https://github.com/micnncim/kubectl-reap
$ brew install kubectl-reap

Via Go

$ go get github.com/micnncim/kubectl-reap/cmd/kubectl-reap

Examples

Pods

In this example, this plugin deletes all Pods whose status is not Running.

bash
$ kubectl get po
NAME          READY   STATUS      RESTARTS   AGE
pod-running   1/1     Running     0          10s
pod-pending   0/1     Pending     0          20s
pod-failed    0/1     Failed      0          30s
pod-unknown   0/1     Unknown     0          40s
job-kqpxc     0/1     Completed   0          50s

$ kubectl reap po
pod/pod-pending deleted
pod/pod-failed deleted
pod/pod-unknown deleted
pod/job-kqpxc deleted

ConfigMaps

In this example, this plugin deletes the unused ConfigMap config-2.

bash
$ kubectl get cm
NAME       DATA   AGE
config-1   1      0m15s
config-2   1      0m10s

$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    volumeMounts:
    - name: config-1-volume
      mountPath: /var/config
  volumes:
  - name: config-1-volume
    configMap:
      name: config-1
EOF

$ kubectl reap cm
configmap/config-2 deleted

Interactive Mode

You can choose which resource you will delete one by one by interactive mode.

bash
$ kubectl reap cm --interactive # or '-i'
? Are you sure to delete configmap/config-1? Yes
configmap/config-1 deleted
? Are you sure to delete configmap/config-2? No
? Are you sure to delete configmap/config-3? Yes
configmap/config-3 deleted

Usage

…

Caveats

  • 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.
  • 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.
  • 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.
    • e.g.) A Secret which isn't used by any Pods or ServiceAccounts but used by cert-manager can be deleted

Background

kubectl apply --prune allows us to delete unused resources. However, it's not very flexible when we want to choose what kind resource to be deleted. This plugin provides more flexible, easy way to delete resources.

Similar Projects

  • dtan4/k8s-unused-secret-detector
  • FikaWorks/kubectl-plugins/prune-unused
  • dirathea/kubectl-unused-volumes

Issues· 11 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gokrewkubectlkubectl-pluginkubernetes

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类云原生
定价开源

> 相关工具

K
Kubernetes
容器编排事实标准
H
Helm
Kubernetes 包管理器
S
seaweedfs
SeaweedFS is a distributed storage system for object storage (S3), file systems, and Iceberg tables,