一个 kubectl 插件,用于删除未使用的 Kubernetes 资源
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.
Download precompiled binaries from GitHub Releases.
$ kubectl krew install reap$ brew tap micnncim/kubectl-reap https://github.com/micnncim/kubectl-reap
$ brew install kubectl-reap$ go get github.com/micnncim/kubectl-reap/cmd/kubectl-reapIn this example, this plugin deletes all Pods whose status is not Running.
$ 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 deletedIn this example, this plugin deletes the unused ConfigMap config-2.
$ 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 deletedYou can choose which resource you will delete one by one by interactive mode.
$ 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…--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.--namespace kube-system or --all-namespaces, this plugin never deletes any resources in kube-system so that it prevents unexpected resource deletion.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.
暂无开放 Issues,或尚未同步最近议题。