micnncim / kubectl-reap Goto Github PK
View Code? Open in Web Editor NEWkubectl plugin that deletes unused Kubernetes resources
License: Apache License 2.0
kubectl plugin that deletes unused Kubernetes resources
License: Apache License 2.0
Hi, I'm trying to use your tool however, I'm unable with all the suggested ways in the readme.
Krew, I can see it in the list already however:
kubectl krew install reap
Updated the local copy of plugin index.
Installing plugin: reap
W1025 14:03:40.703125 98490 install.go:164] failed to install plugin "reap": plugin "reap" does not offer installation for this platform
failed to install some plugins: [reap]: plugin "reap" does not offer installation for this platform
brew gives the following error Error: kubectl-reap: wrong number of arguments (given 1, expected 0)
on three different machines.
is this still maintained? Thank you
I am using https://github.com/external-secrets/kubernetes-external-secrets to manage secrets via AWS Secrets Manager.
Do you have any plans to support such custom resources with this plugin?
I am glad if external-secrets will also be supported (and also thinking about forking this plugin to support external-secrets if not planned).
$ go build cmd/kubectl-reap/main.go
...
go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
# golang.org/x/sys/unix
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/syscall_darwin.1_13.go:29:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.1_13.go:27:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.1_13.go:40:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:28:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:43:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:59:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:75:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:90:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:105:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:121:3: //go:linkname must refer to declared function or variable
../../.asdf/installs/golang/1.19.1/packages/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:121:3: too many errors
kubectl prune configmap --all-namespaces --dry-run=client
configmap/object-bucket-claim deleted (dry run)
configmap/helm-operator-kube-config deleted (dry run)
configmap/skyblock deleted (dry run)
configmap/cluster-info deleted (dry run)
configmap/cert-manager-cainjector-leader-election deleted (dry run)
configmap/cert-manager-cainjector-leader-election-core deleted (dry run)
configmap/cert-manager-controller deleted (dry run)
configmap/extension-apiserver-authentication deleted (dry run)
configmap/kubeadm-config deleted (dry run)
configmap/kubelet-config-1.18 deleted (dry run)
configmap/linkerd-config-addons deleted (dry run)
configmap/bungee-op-lock deleted (dry run)
configmap/nslock-op-lock deleted (dry run)
configmap/object-bucket-claim deleted (dry run)
configmap/server-op-lock deleted (dry run)
configmap/sftp-op-lock deleted (dry run)
configmap/config deleted (dry run)
configmap/prom-operator-grafana-test deleted (dry run)
configmap/prom-operator-prometheus-o-apiserver deleted (dry run)
configmap/prom-operator-prometheus-o-cluster-total deleted (dry run)
configmap/prom-operator-prometheus-o-controller-manager deleted (dry run)
configmap/prom-operator-prometheus-o-etcd deleted (dry run)
configmap/prom-operator-prometheus-o-grafana-datasource deleted (dry run)
configmap/prom-operator-prometheus-o-k8s-coredns deleted (dry run)
configmap/prom-operator-prometheus-o-k8s-resources-cluster deleted (dry run)
configmap/prom-operator-prometheus-o-k8s-resources-namespace deleted (dry run)
configmap/prom-operator-prometheus-o-k8s-resources-node deleted (dry run)
configmap/prom-operator-prometheus-o-k8s-resources-pod deleted (dry run)
configmap/prom-operator-prometheus-o-k8s-resources-workload deleted (dry run)
configmap/prom-operator-prometheus-o-k8s-resources-workloads-namespace deleted (dry run)
configmap/prom-operator-prometheus-o-kubelet deleted (dry run)
configmap/prom-operator-prometheus-o-namespace-by-pod deleted (dry run)
configmap/prom-operator-prometheus-o-namespace-by-workload deleted (dry run)
configmap/prom-operator-prometheus-o-node-cluster-rsrc-use deleted (dry run)
configmap/prom-operator-prometheus-o-node-rsrc-use deleted (dry run)
configmap/prom-operator-prometheus-o-nodes deleted (dry run)
configmap/prom-operator-prometheus-o-persistentvolumesusage deleted (dry run)
configmap/prom-operator-prometheus-o-pod-total deleted (dry run)
configmap/prom-operator-prometheus-o-prometheus deleted (dry run)
configmap/prom-operator-prometheus-o-proxy deleted (dry run)
configmap/prom-operator-prometheus-o-scheduler deleted (dry run)
configmap/prom-operator-prometheus-o-statefulset deleted (dry run)
configmap/prom-operator-prometheus-o-workload-total deleted (dry run)
configmap/ingress-controller-leader-nginx deleted (dry run)
configmap/nginx-nginx-ingress-tcp deleted (dry run)
configmap/ceph-delete-bucket deleted (dry run)
configmap/object-bucket-claim deleted (dry run)
configmap/local-device-amd1 deleted (dry run)
configmap/local-device-amd2 deleted (dry run)
configmap/local-device-s1 deleted (dry run)
configmap/local-device-s2 deleted (dry run)
configmap/local-device-s3 deleted (dry run)
configmap/rook-ceph-operator-config deleted (dry run)
configmap/rook-ceph-pdbstatemap deleted (dry run)
Ran it as a test. Looks useful and I know that this is the purpose of dry-run. Though I'd say when using --all-namespaces
some kube-system default config maps should be ignored least. Specifically:
configmap/kubeadm-config deleted (dry run)
configmap/kubelet-config-1.18 deleted (dry run)
what is the purpose of removing pods?
Do they have to start successful after deletion ?
If pod in pending waiting some resource, it won't help it
if pod in CrashLoopBackOff status , it won't help it
What do you think about to add scaling deployment of such notworking pods to 0 ?
This works for small cluster but failed for a large cluster, in this case, there were more than 5.5k HPA
$ kubectl reap hpa --all-namespaces --dry-run=client -ojson | jq -s . | jq -r '["NAMESPACE","HPA_NAME","CREATION_TIMESTAMP","LAST_USED_TIMESTAMP"],(.[] | [.metadata.namespace, .metadata.name, .metadata.creationTimestamp, .status.lastScaleTime]) | @tsv' | column -ts $'\t'
Error from server (Expired): The provided continue parameter is too old to display a consistent list result. You can start a new list without the continue parameter, or use the continue token in this response to retrieve the remainder of the results. Continuing with the provided token results in an inconsistent list - objects that were created, modified, or deleted between the time the first chunk was returned and now may show up in the list.
When I run brew install kubectl-reap
the output is:
Error: micnncim/kubectl-reap/kubectl-reap: wrong number of arguments (given 1, expected 0)
Getting these warnings on every brew operation.
Warning: Calling bottle :unneeded is deprecated! There is no replacement.
Please report this issue to the micnncim/kubectl-reap tap (not Homebrew/brew or Homebrew/core):
/usr/local/Homebrew/Library/Taps/micnncim/homebrew-kubectl-reap/Formula/kubectl-reap.rb:9
can we please add some exclusion feature for secret/configmaps which are referred in replica sets, which might be helpful while rolling back a deployment. And replicaset are automatically getting cleaned up based on .spec.revisionHistoryLimit
of Deployment.
(Similiar to #120)
I've found that ConfigMaps used by CronJobs for eg. env vars are not detected as in-use.
apiVersion: batch/v1
kind: CronJob
metadata:
name: test
spec:
jobTemplate:
spec:
template:
spec:
containers:
- env:
- name: TEST
valueFrom:
configMapKeyRef:
key: TEST
name: test-config
Output from kubectl reap cm
:
configmap/test-config deleted
spec:
imagePullSecrets:
- name: coding-devos-regcred
secret/coding-devos-regcred deleted (dry run)
Ingress resources can use secrets to store TLS certificates, such as those managed by Cert Manager. Kubectl-reap currently detects these secrets are not in use and suggests removing them.
Eg
$ kubectl get secret
NAME TYPE DATA AGE
default-token-ggbbh kubernetes.io/service-account-token 3 521d
review-41-enquiry-4r57wt-secret Opaque 3 10d
review-41-enquiry-4r57wt-tls kubernetes.io/tls 3 10d
#The review-41-enquiry-4r57wt-secret is used by a pod
$ kubectl reap secret --dry-run=client
secret/review-41-enquiry-4r57wt-tls deleted (dry run)
$ kubectl get ingress review-41-enquiry-4r57wt -o yaml
#partly redacted
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "true"
spec:
rules:
- host: 41-enquiry.example.com
http:
paths:
- backend:
service:
name: review-41-enquiry-4r57wt
port:
number: 8000
path: /
pathType: Prefix
tls:
- hosts:
- 41-enquiry.example.com
secretName: review-41-enquiry-4r57wt-tls
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.