Skip to content

colwill/ooc-controller

Repository files navigation

OOC Controller

This is a really simple controller used in a side-project for raising OOCKilled (Out of Compute / Out of CPU) when exceeding CPU limits in a cluster. Works in a similar way to OOMKilled (when a pod exceeds memory limits).

Latest tag: docker pull colwill/ooc-controller:v1.0.0

Please ⭐ if you find this useful 💚

How It Works

Controller polls Kubernetes Metrics API for CPU usage across all running pods. For each container it compares usage against the container's limits.cpu (or requests.cpu, configurable). If usage exceeds the threshold, the pod is killed and a Kubernetes Warning event is raised against it with OOCKilled as the reason.

NAMESPACE   LAST SEEN   TYPE      REASON      OBJECT         MESSAGE
default     1s          Warning   OOCKilled   pod/test-123   CPU limits: using 750m, limits is 500m

Config

Example config file (note: kube-system & kube-public are ignored in default.yaml):

ignore:
  namespace:
    - dev
    - prod
  deployments:
    - myapp
pollInterval: "30s"
# compare against "limits" or "requests"
thresholdSource: "limits"

Quick Start

Prerequisites for development

  • Go 1.25+
  • Docker
  • kind
  • kubectl

Local Dev

make kind-up
kubectl logs -f -n ooc-system deployment/ooc-controller
kubectl get events --all-namespaces --field-selector reason=OOCKilled -w
make deploy-local
make test-e2e
make kind-down

Build + Test

make build
make test
make lint
make docker-build

Deployment

Deploy to a Cluster

The controller requires metrics-server to be installed in the target cluster.

# Deploy with default configuration
kubectl apply -k deploy/manifests/

# Or customise the ConfigMap first
kubectl edit configmap ooc-controller-config -n ooc-system
kubectl rollout restart deployment/ooc-controller -n ooc-system

RBAC

The controller needs the following permissions:

  • get, list, watch, delete on pods (core API)
  • get, list on pods (metrics.k8s.io API)
  • create, patch on events (core API)

These are defined in deploy/manifests/rbac.yaml.

About

OOCKilled is OOMKilled for CPU

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors