Skip to content

u2i/auto-spin-down-operator

Repository files navigation

Auto Spin Down Operator

A Kubernetes operator that automatically shuts down specified deployments at 8:00AM UTC.

Overview

This operator watches for ScheduledShutdown custom resources and automatically scales down the specified deployments to 0 replicas at the configured time (default: 08:00 UTC).

Features

  • Schedule automatic shutdown of deployments at specific times
  • Tracks the original replica count before shutdown
  • Prevents duplicate shutdowns on the same day
  • Cluster-scoped CRD for managing shutdowns across namespaces
  • HTTP webhook endpoint for restoring deployments on-demand

Installation

Using Helm (Recommended)

helm install auto-spin-down-operator ./charts/auto-spin-down-operator \
  --namespace auto-spin-down-operator-system \
  --create-namespace

Or from a Helm repository (once published):

helm repo add u2i https://u2i.github.io/helm-charts
helm install auto-spin-down-operator u2i/auto-spin-down-operator \
  --namespace auto-spin-down-operator-system \
  --create-namespace

With custom values:

helm install auto-spin-down-operator ./charts/auto-spin-down-operator \
  --namespace auto-spin-down-operator-system \
  --create-namespace \
  --set image.tag=v0.1.0 \
  --set resources.limits.memory=256Mi

Using Terraform

resource "helm_release" "auto_spin_down_operator" {
  name             = "auto-spin-down-operator"
  chart            = "./charts/auto-spin-down-operator"
  namespace        = "auto-spin-down-operator-system"
  create_namespace = true

  set {
    name  = "image.tag"
    value = "v0.1.0"
  }
}

Using kubectl

  1. Install the CRD:
make install-crd
  1. Deploy the operator:
make deploy

Or build and deploy with custom image:

make docker-build IMG=<your-registry>/auto-spin-down-operator:latest
make docker-push IMG=<your-registry>/auto-spin-down-operator:latest
make deploy IMG=<your-registry>/auto-spin-down-operator:latest

Usage

Create a ScheduledShutdown resource to schedule a deployment shutdown:

apiVersion: autoshutdown.example.com/v1alpha1
kind: ScheduledShutdown
metadata:
  name: example-shutdown
spec:
  deploymentName: my-app
  namespace: default
  shutdownTime: "08:00"

Apply it:

kubectl apply -f config/samples/scheduledshutdown_sample.yaml

Configuration

  • deploymentName: Name of the deployment to shut down
  • namespace: Namespace where the deployment exists
  • shutdownTime: Time in HH:MM format (UTC timezone)

Restoring Deployments

After a deployment has been shut down, you can restore it to its original replica count using the HTTP webhook:

curl http://auto-spin-down-operator-webhook.auto-spin-down-operator-system.svc.cluster.local:8081/spinup/example-shutdown

Replace example-shutdown with the name of your ScheduledShutdown resource.

The endpoint will:

  • Restore the deployment to its original replica count (stored before shutdown)
  • Update the status phase to "Running"
  • Return a JSON response with the details

Note: The webhook service is only accessible within the cluster (ClusterIP). For external access from your NAT subnet, you can use kubectl port-forward:

kubectl port-forward -n auto-spin-down-operator-system svc/auto-spin-down-operator-webhook 8081:8081

Then access via:

curl http://localhost:8081/spinup/example-shutdown

Development

Run locally:

make run

Build binary:

make build

Uninstall

Helm

helm uninstall auto-spin-down-operator -n auto-spin-down-operator-system

kubectl

make undeploy

About

Kubernetes operator that automatically shuts down deployments at scheduled times

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •