Skip to content

Commit 5bdef41

Browse files
author
Zeusro
committed
Tue Jan 6 23:20:49 CST 2026
1 parent 5697a28 commit 5bdef41

18 files changed

Lines changed: 247 additions & 127 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
# project
2424
config.yaml
2525
operator/cmd/manager/kube-killer
26+
kubectl-kill

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ auto_commit:
1414
build:
1515
GOARCH=$(ARCH) CGO_ENABLED=0 go build
1616

17+
build-kubectl-plugin:
18+
GOARCH=$(ARCH) CGO_ENABLED=0 go build -o kubectl-kill ./cmd/kubectl-kill
19+
1720
buildAndRun: build run
1821

1922
fix-dep:
@@ -57,3 +60,15 @@ update-dep: update-mod fix-dep
5760
update-mod:
5861
go get -u -v github.com/p-program/go-common-library
5962
# go-mod-upgrade
63+
64+
# Install kubectl-kill plugin to ~/bin or /usr/local/bin
65+
# Usage: make install-kubectl-plugin [PREFIX=/usr/local]
66+
install-kubectl-plugin: build-kubectl-plugin
67+
@if [ -z "$(PREFIX)" ]; then \
68+
PREFIX=$$HOME/bin; \
69+
fi; \
70+
mkdir -p $$PREFIX; \
71+
cp kubectl-kill $$PREFIX/; \
72+
chmod +x $$PREFIX/kubectl-kill; \
73+
echo "kubectl-kill plugin installed to $$PREFIX/kubectl-kill"; \
74+
echo "Make sure $$PREFIX is in your PATH"

README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ custom metrics or custom condition.
2121

2222
It is a humane killer, he could also freeze the deploy without killing it (scale to 0).
2323

24-
It is very lightweight and easy to use, you don't need to install any CRD.
25-
2624
You could run as web server, binary and CLI mode.
2725

2826
## Architecture
@@ -183,8 +181,6 @@ The status will show:
183181

184182
Once the [kube-killer server](#Web-server-mode) is ready,you can use the CLI mode .
185183

186-
TODO 下发一个token 供本地调用。
187-
188184
#### kill resource
189185

190186
```bash
@@ -225,30 +221,56 @@ Finally,you are free to destroy the whole production Kubernetes cluster remot
225221

226222
## Serverless mode
227223

228-
1. [ ] freeze resource = kubectl scale --replicas=0 statefulset/web
224+
1. [ ] kill node gracefully
225+
1. [ ] kill satan
229226
1. [x] kill completed/failed pod automatically
230227
1. [x] kill unused PV
231228
1. [x] kill unused PVC
232229
1. [x] kill service without pod
233-
1. [ ] kill node gracefully
234-
1. [ ] kill satan
235-
1. [ ] kill stucking namespace
236-
1. [ ] kill unused configmap
230+
1. [x] kill unused configmap
237231
1. [x] kill unused secret
238-
1. [ ] output event
239-
1. [ ] custom metrics condition support
232+
1. [x] kill completed jobs
233+
1. [x] 支持 all-namespaces 标志
234+
1. [x] 支持 interactive 模式
235+
1. [x] 支持 dry-run 模式
236+
237+
### kubectl Plugin
238+
239+
kube-killer can be used as a kubectl plugin! Install it and use `kubectl kill` to delete unused Kubernetes resources.
240+
241+
**Installation:**
240242

241243
```bash
244+
# Build and install the plugin
245+
# 构建插件
246+
make build-kubectl-plugin
247+
# 安装插件
248+
make install-kubectl-plugin
249+
250+
# Or install to a custom location
251+
make install-kubectl-plugin PREFIX=/usr/local/bin
242252

243253
```
244254

245-
### Binary usage
255+
**Usage:**
246256

247257
```bash
258+
# Delete unused pods
259+
kubectl kill pod
260+
261+
# Delete unused pods in all namespaces
262+
kubectl kill pod -A
248263

264+
# Dry run to see what would be deleted
265+
kubectl kill pod -d
266+
267+
# Delete unused services
268+
kubectl kill service -n default
249269
```
250270

251-
### CLI usage
271+
For more details, see the [kubectl plugin documentation](docs/KUBECTL_PLUGIN.md).
272+
273+
### Binary CLI usage
252274

253275
```bash
254276
kube-killer kill po

cmd/killer/kill.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,33 @@ func SelectKiller(args []string) error {
289289
func getKubernetesClient() (*kubernetes.Clientset, error) {
290290
return kubernetes.NewForConfig(core.GLOBAL_KUBERNETES_CONFIG)
291291
}
292+
293+
// ExecuteKill executes the kill operation with the given parameters
294+
// This function is designed for use by kubectl plugins and other external callers
295+
func ExecuteKill(resourceType, ns string, allNs, dry, interactiveMode bool) error {
296+
// Set package-level variables temporarily
297+
oldNamespace := namespace
298+
oldAllNamespaces := allNamespaces
299+
oldDryRun := dryRun
300+
oldInteractive := interactive
301+
302+
namespace = ns
303+
allNamespaces = allNs
304+
dryRun = dry
305+
interactive = interactiveMode
306+
307+
if allNamespaces {
308+
namespace = ""
309+
}
310+
311+
// Execute the kill operation
312+
err := SelectKiller([]string{resourceType})
313+
314+
// Restore old values (though they may not be needed if this is the only caller)
315+
namespace = oldNamespace
316+
allNamespaces = oldAllNamespaces
317+
dryRun = oldDryRun
318+
interactive = oldInteractive
319+
320+
return err
321+
}

cmd/killer/resource_killer.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
package killer
22

3-
import (
4-
pkg "github.com/p-program/kube-killer/pkg/condition"
5-
appv1 "k8s.io/api/apps/v1"
6-
)
7-
8-
func init() {
9-
10-
}
11-
3+
// ResourceKiller is a placeholder for future conditional resource killing functionality
4+
// This is not currently implemented or used
125
type ResourceKiller struct {
136
}
147

15-
func (k *ResourceKiller) KillByCondition(resource interface{}, condition pkg.Condition) {
16-
switch resource.(type) {
17-
case appv1.Deployment:
18-
break
19-
20-
}
21-
22-
// resourceType core.ResourceType, name string
8+
// KillByCondition is a placeholder method for future conditional resource killing
9+
// This is not currently implemented
10+
func (k *ResourceKiller) KillByCondition(resource interface{}, condition interface{}) {
11+
// TODO: Implement conditional resource killing
12+
// This would allow killing resources based on custom conditions/metrics
2313
}
2414

2515
func (k *ResourceKiller) kill() {
26-
16+
// TODO: Implement
2717
}

config/projectconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package config
22

33
import (
4-
"io/ioutil"
4+
"os"
55

66
"github.com/p-program/go-common-library/text"
77
"gopkg.in/yaml.v2"
@@ -21,7 +21,7 @@ func NewProjectConfig() *ProjectConfig {
2121

2222
// LoadYAML LoadYAML from file
2323
func (config *ProjectConfig) LoadYAML(path string) error {
24-
content, err := ioutil.ReadFile(path)
24+
content, err := os.ReadFile(path)
2525
contentWithoutComment := []byte(text.RemoveYAMLcomment(string(content)))
2626
if err != nil {
2727
return err

core/global-config.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/global-config_test.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

core/resource-builder.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/types.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)