Skip to content

Commit 082476f

Browse files
author
Zeusro
committed
Mon Jan 5 22:01:05 CST 2026
1 parent f28a561 commit 082476f

15 files changed

Lines changed: 1152 additions & 51 deletions

File tree

README.md

Lines changed: 102 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,70 +53,132 @@ Just remember:
5353

5454
## Server mode
5555

56-
### TODO
56+
kube-killer can run as a Kubernetes Operator that watches `KubeKiller` Custom Resources and automatically cleans up Kubernetes resources based on the configured mode and schedule.
5757

58-
1. [ ] kube-killer prepare
59-
1. [ ] prepare MYSQL
60-
1. [ ] prepare kube-killer server
61-
1. [ ] crashbackoff --> freeze deploy
62-
1. [ ] kill me
58+
### Installation
59+
60+
1. Install the CRD:
6361

6462
```bash
65-
git clone https://github.com/p-program/kube-killer.git
66-
make build
67-
cp config/config-example.yaml config/config.yaml
68-
69-
# edit config.yaml depending on the actual situation
70-
vi config/config.yaml
71-
......
72-
73-
./kube-killer prepare
74-
# It will create
75-
# 1. MYSQL database
76-
# 2. `kube-killer` web server
63+
kubectl apply -f deploy/operator/crd.yaml
7764
```
7865

79-
After that,you have two options: To be a demon or to be a Illidan(demon hunter).
66+
2. Deploy the Operator:
8067

81-
### demon mode
68+
```bash
69+
kubectl apply -f deploy/operator/rbac.yaml
70+
kubectl apply -f deploy/operator/deployment.yaml
71+
```
72+
73+
3. Verify the operator is running:
8274

8375
```bash
84-
./kube-killer run -mode demon
76+
kubectl get pods -n kube-system | grep kube-killer
8577
```
8678

87-
When `kube-killer` run on the demon mode,It will KILL ALL PODS AT EVERY PERIOD.
79+
### Usage
8880

89-
Pods whoever create will be killed.
81+
After deploying the operator, you can create `KubeKiller` resources to control the cleanup behavior.
9082

91-
It is unstoppable.
83+
#### Demon Mode
9284

93-
### Illidan mode
85+
Demon mode will **KILL ALL PODS** at every interval. It is unstoppable and will kill any pod that gets created.
9486

95-
```bash
96-
./kube-killer run -mode Illidan
87+
```yaml
88+
apiVersion: kubekiller.p-program.github.io/v1alpha1
89+
kind: KubeKiller
90+
metadata:
91+
name: kube-killer-demon
92+
namespace: default
93+
spec:
94+
mode: demon
95+
interval: "5m"
96+
dryRun: false
9797
```
9898
99-
When `kube-killer` run on the demon mode,it will hunt all unhealthy kubernetes resources at every period.
99+
Apply it:
100100
101-
Such as
102-
1.
103-
1.
104-
1.
105-
1.
106-
1.
101+
```bash
102+
kubectl apply -f - <<EOF
103+
apiVersion: kubekiller.p-program.github.io/v1alpha1
104+
kind: KubeKiller
105+
metadata:
106+
name: kube-killer-demon
107+
namespace: default
108+
spec:
109+
mode: demon
110+
interval: "5m"
111+
dryRun: false
112+
EOF
113+
```
107114

108-
#### kill resource
115+
**⚠️ WARNING**: Demon mode will kill ALL pods in all namespaces (except kube-system) at the specified interval. Use with extreme caution!
116+
117+
#### Illidan Mode
118+
119+
Illidan mode hunts unhealthy Kubernetes resources at every period. It will clean up:
120+
- Completed/Failed pods
121+
- Completed jobs
122+
- Unused PVCs and PVs
123+
- Services without pods
124+
- Unused ConfigMaps and Secrets
125+
126+
```yaml
127+
apiVersion: kubekiller.p-program.github.io/v1alpha1
128+
kind: KubeKiller
129+
metadata:
130+
name: kube-killer-illidan
131+
namespace: default
132+
spec:
133+
mode: illidan
134+
interval: "10m"
135+
dryRun: false
136+
resources:
137+
- pod
138+
- job
139+
- pvc
140+
- pv
141+
- service
142+
- configmap
143+
- secret
144+
excludeNamespaces:
145+
- kube-system
146+
- kube-public
147+
- kube-node-lease
148+
```
109149
110-
```go
111-
TODO curl
150+
Apply it:
151+
152+
```bash
153+
kubectl apply -f deploy/operator/example.yaml
112154
```
113155

114-
#### freeze deploy
156+
### Configuration Options
157+
158+
The `KubeKiller` CRD supports the following configuration:
159+
160+
- **mode**: Operation mode - `demon` (kills all pods) or `illidan` (hunts unhealthy resources)
161+
- **interval**: How often the killer should run (e.g., "5m", "1h", "30s")
162+
- **namespaces**: Specific namespaces to operate on (empty means all except kube-system)
163+
- **excludeNamespaces**: Namespaces to exclude from operations
164+
- **dryRun**: If true, only log what would be deleted without actually deleting
165+
- **resources**: Resource types to kill (only used in illidan mode): pod, job, pvc, pv, service, configmap, secret
115166

116-
```go
117-
TODO curl
167+
### Monitoring
168+
169+
Check the status of your KubeKiller resources:
170+
171+
```bash
172+
kubectl get kubekiller
173+
kubectl describe kubekiller kube-killer-illidan
118174
```
119175

176+
The status will show:
177+
- `lastRunTime`: When the killer last ran
178+
- `lastRunResult`: Result of the last run
179+
- `resourcesKilled`: Number of resources killed
180+
- `phase`: Current phase (Ready, Running, Error)
181+
120182
### CLI usage
121183

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

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66

77
"github.com/p-program/kube-killer/cmd/killer"
8+
"github.com/p-program/kube-killer/cmd/server"
89
"github.com/spf13/cobra"
910
"github.com/spf13/viper"
1011
)
@@ -42,6 +43,7 @@ func init() {
4243
func bindCommand() {
4344
rootCmd.AddCommand(NewVersionCommand())
4445
rootCmd.AddCommand(NewFreezeCommand())
46+
rootCmd.AddCommand(server.NewServerCommand())
4547
kill := killer.NewKillCommand()
4648
rootCmd.AddCommand(kill)
4749
kill.AddCommand()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Package v1alpha1 contains API Schema definitions for the kube-killer v1alpha1 API group
2+
// +kubebuilder:object:generate=true
3+
// +groupName=kubekiller.p-program.github.io
4+
package v1alpha1
5+
6+
import (
7+
"k8s.io/apimachinery/pkg/runtime/schema"
8+
"sigs.k8s.io/controller-runtime/pkg/scheme"
9+
)
10+
11+
var (
12+
// GroupVersion is group version used to register these objects
13+
GroupVersion = schema.GroupVersion{Group: "kubekiller.p-program.github.io", Version: "v1alpha1"}
14+
15+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
16+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
17+
18+
// AddToScheme adds the types in this group-version to the given scheme.
19+
AddToScheme = SchemeBuilder.AddToScheme
20+
)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// KubeKillerSpec defines the desired state of KubeKiller
8+
type KubeKillerSpec struct {
9+
// Mode defines the operation mode: "demon" or "illidan"
10+
// +kubebuilder:validation:Enum=demon;illidan
11+
// +kubebuilder:default=illidan
12+
Mode string `json:"mode,omitempty"`
13+
14+
// Interval defines how often the killer should run (e.g., "5m", "1h")
15+
// +kubebuilder:default="5m"
16+
Interval string `json:"interval,omitempty"`
17+
18+
// Namespaces to operate on. Empty means all namespaces except kube-system
19+
// +optional
20+
Namespaces []string `json:"namespaces,omitempty"`
21+
22+
// ExcludeNamespaces namespaces to exclude from operations
23+
// +optional
24+
ExcludeNamespaces []string `json:"excludeNamespaces,omitempty"`
25+
26+
// DryRun if true, only log what would be deleted without actually deleting
27+
// +kubebuilder:default=false
28+
DryRun bool `json:"dryRun,omitempty"`
29+
30+
// Resources defines which resource types to kill
31+
// +optional
32+
Resources []string `json:"resources,omitempty"`
33+
}
34+
35+
// KubeKillerStatus defines the observed state of KubeKiller
36+
type KubeKillerStatus struct {
37+
// LastRunTime is the last time the killer ran
38+
// +optional
39+
LastRunTime *metav1.Time `json:"lastRunTime,omitempty"`
40+
41+
// LastRunResult shows the result of the last run
42+
// +optional
43+
LastRunResult string `json:"lastRunResult,omitempty"`
44+
45+
// ResourcesKilled is the number of resources killed in the last run
46+
// +optional
47+
ResourcesKilled int `json:"resourcesKilled,omitempty"`
48+
49+
// Phase indicates the current phase of the operator
50+
// +optional
51+
Phase string `json:"phase,omitempty"`
52+
}
53+
54+
// +kubebuilder:object:root=true
55+
// +kubebuilder:subresource:status
56+
// +kubebuilder:printcolumn:name="Mode",type="string",JSONPath=".spec.mode"
57+
// +kubebuilder:printcolumn:name="Interval",type="string",JSONPath=".spec.interval"
58+
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
59+
// +kubebuilder:printcolumn:name="LastRun",type="date",JSONPath=".status.lastRunTime"
60+
// +kubebuilder:printcolumn:name="Killed",type="integer",JSONPath=".status.resourcesKilled"
61+
62+
// KubeKiller is the Schema for the kubekillers API
63+
type KubeKiller struct {
64+
metav1.TypeMeta `json:",inline"`
65+
metav1.ObjectMeta `json:"metadata,omitempty"`
66+
67+
Spec KubeKillerSpec `json:"spec,omitempty"`
68+
Status KubeKillerStatus `json:"status,omitempty"`
69+
}
70+
71+
// +kubebuilder:object:root=true
72+
73+
// KubeKillerList contains a list of KubeKiller
74+
type KubeKillerList struct {
75+
metav1.TypeMeta `json:",inline"`
76+
metav1.ListMeta `json:"metadata,omitempty"`
77+
Items []KubeKiller `json:"items"`
78+
}
79+
80+
func init() {
81+
SchemeBuilder.Register(&KubeKiller{}, &KubeKillerList{})
82+
}

0 commit comments

Comments
 (0)