pod-cleaner

by lbenicio

Helm chartv0.1.1App latestVerified publisher

CronJob that periodically cleans up completed pods

About this chart

pod-cleaner

A Helm chart that deploys a CronJob to periodically clean up completed (Succeeded) pods from the cluster.

TL;DR

helm repo add lbenicio-community https://helm.lbenicio.dev/
helm install my-release lbenicio-community/pod-cleaner

Introduction

This chart deploys a Kubernetes CronJob that runs kubectl delete pod --field-selector=status.phase=Succeeded on a configurable schedule. It uses bitnami/kubectl as the container image.

Prerequisites

  • Kubernetes 1.19+
  • Helm 3.x+
  • ClusterRole RBAC permissions (the chart creates its own ClusterRole and ClusterRoleBinding)

RBAC

The chart creates:

  • ServiceAccount — identity for the CronJob pods
  • ClusterRole — grants list and delete verbs on pods resources
  • ClusterRoleBinding — binds the ServiceAccount to the ClusterRole

Installing the Chart

helm install my-release lbenicio-community/pod-cleaner --namespace default

Parameters

KeyTypeDefaultDescription
image.repositorystringbitnami/kubectlContainer image repository
image.tagstringlatestImage tag (defaults to Chart.appVersion)
image.pullPolicystringIfNotPresentImage pull policy
schedulestring0 * * * *Cron schedule for the cleanup job
namespacestringdefaultNamespace to clean up pods from
successfulJobsHistoryLimitint1Number of successful jobs to keep
failedJobsHistoryLimitint1Number of failed jobs to keep
resources.requests.cpustring10mCPU request
resources.requests.memorystring64MiMemory request
resources.limits.cpustring50mCPU limit
resources.limits.memorystring128MiMemory limit
nodeSelectorobject{}Node selector for pod assignment
tolerationslist[]Tolerations for pod assignment
affinityobject{}Affinity for pod assignment
serviceAccount.createbooltrueCreate a ServiceAccount
serviceAccount.namestring""ServiceAccount name (defaults to fullname)

Configuration

Custom schedule

schedule: "*/30 * * * *"   # Every 30 minutes

Target a specific namespace

namespace: "production"

Run on control-plane nodes

tolerations:
  - key: node-role.kubernetes.io/control-plane
    operator: Exists
    effect: NoSchedule

License

This chart is licensed under GPLv3.


Made with ❤️ by lbenicio

Deploy pod-cleaner with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has pod-cleaner on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartpod-cleaner is pinned at v0.1.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply