Kubernetes operator that scales a Deployment from Redis Stream consumer-group backlog (pending + lag), using scaling logic in autoscaler-engine.
- Watches
RedisStreamScalerCRs and the targetDeployment - Reads backlog via Redis
XINFO GROUPS - Sets
Deployment.spec.replicaswith min/max,tasksPerPod, and scale-down cooldown after scale-up - Leader election enabled by default (single active reconciler)
Each reconcile (on a timer and when the CR or target Deployment changes):
- Backlog —
XINFO GROUPSonstreamName; forgroupName, backlog =pending + lag(unclaimed messages plus messages not yet delivered to consumers). - Desired replicas —
ceil(backlog / tasksPerPod), then clamped tominReplicas…maxReplicas. - Apply — patch
Deployment.spec.replicaswhen desired differs from current.
Scale-up happens as soon as backlog needs more pods. Scale-down is delayed: for cooldownPeriod after the last scale-up, the operator will not reduce replicas even if backlog drops (scale-down is allowed once that window passes). That asymmetry gives workers time to finish in-flight work; pair it with a sensible terminationGracePeriodSeconds on the worker Deployment.
Scaling logic lives in autoscaler-engine; this operator wires it to Kubernetes and Redis. Do not run HPA on the same Deployment.
api/v1alpha1/ CRD types (+ kubebuilder markers)
internal/controller/ Reconciler and Redis/Deployment adapters
cmd/main.go Manager entrypoint
config/ Kustomize (CRD, RBAC, manager, default bundle)
docs/deploy.md Deploy to rbpi
hack/boilerplate.go.txt License header for make generate
make manifests generate
make test
make lintexport KUBECONFIG=/path/to/alesrpi-lab-iac/kubeconfig.yaml
make deploy-rbpiDetails: docs/deploy.md.
With operator, Redis, worker Deployment, and the sample CR applied:
make scale-load
make scale-observe
make scale-load-clearspec:
scaleTargetRef: worker-deployment
redisAddr: redis.default.svc.cluster.local:6379
streamName: events
groupName: workers
minReplicas: 1
maxReplicas: 5
tasksPerPod: 10
cooldownPeriod: 30s
pollInterval: 5sApache License 2.0. See LICENSE.