A Kubernetes pod reaper
This repository has been archived on 2023-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
2022-12-30 20:05:40 +00:00
.agola feat(ci): run renovate bot 2022-09-27 21:59:50 +02:00
.github/workflows Update goreleaser/goreleaser-action action to v3 2022-05-22 00:41:31 +00:00
deployments MVP 2022-04-13 21:00:32 +02:00
reaper refactor: move to custom Gitea 2022-09-22 10:54:06 +02:00
scripts MVP 2022-04-13 21:00:32 +02:00
testdata Update docs 2022-04-13 21:32:45 +02:00
.editorconfig Add editorconfig 2022-05-13 14:46:25 +02:00
.gitignore feat(ci): run renovate bot 2022-09-27 21:59:50 +02:00
.golangci.yml refactor: move to custom Gitea 2022-09-22 10:54:06 +02:00
.goreleaser.yaml Update deps and add container manifests 2022-05-13 14:21:12 +02:00
.pre-commit-config.yaml Add tests and run them in CI 2022-04-14 16:47:47 +02:00
go.mod fix(deps): update module go.uber.org/zap to v1.24.0 2022-12-30 20:05:40 +00:00
go.sum fix(deps): update module go.uber.org/zap to v1.24.0 2022-12-30 20:05:40 +00:00
LICENSE Initial commit 2022-04-13 07:38:40 +02:00
main.go refactor: move to custom Gitea 2022-09-22 10:54:06 +02:00
README.md refactor: move to custom Gitea 2022-09-22 10:54:06 +02:00
renovate.json Add renovate.json 2022-04-13 05:38:48 +00:00
Tiltfile MVP 2022-04-13 21:00:32 +02:00

kreaper - Kubernetes Reaper

Go Report Card

kreaper is (yet another) Kubernetes pod reaper. It's main purpose is to delete pods matching a certain pod selector after a deadline is reached.

The testdata/ directory contains a Kubernetes manifest example how to deploy kreaper as Job that is automatically cleaned after 30s.

Configuration

kreaper only requires a few config options that are available as CLI flags or as environment variables. For the sake of simplicity environment variables are favored.

Env Flag Purpose Example Default
KREAPER_TARGET -target Target selection in the form of key=value app.kubernetes.io/name=ee8dcc4d ""
KREAPER_TARGET_NAMESPACE -target-namespace Namespace in which pods are watched and deleted my-app default
KREAPER_DRY_RUN -dry-run Skip actual deletion true false
KREAPER_LIFETIME -lifetime Duration after which all pods matching the target are deleted 30s 5m

Kubeconfig

kreaper is meant to be running within a Kubernetes cluster and therefore tries at first to read a in-cluster API config. If it fails to read the in-cluster config it tries to read the default $HOME/.kube/config file. The config file location can be modified either with the KUBECONFIG environment variable or by supplying a -kubeconfig flag.

RBAC

kreaper only needs:

  • list
  • watch
  • deletecollection

permissions for Pods in the KREAPER_TARGET_NAMESPACE. A very basic Role would look like so:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: kreaper
rules:
  - verbs:
      - list
      - watch
      - deletecollection
    apiGroups:
      - ""
    resources:
      - pods

alternatively a RoleBinding or a ClusterRoleBinding to the edit ClusterRole might be a little bit overkill but therefore also possible.