A Kubernetes operator that automatically shuts down specified deployments at 8:00AM UTC.
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).
- 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
helm install auto-spin-down-operator ./charts/auto-spin-down-operator \
--namespace auto-spin-down-operator-system \
--create-namespaceOr 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-namespaceWith 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=256Miresource "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"
}
}- Install the CRD:
make install-crd- Deploy the operator:
make deployOr 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:latestCreate 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.yamldeploymentName: Name of the deployment to shut downnamespace: Namespace where the deployment existsshutdownTime: Time in HH:MM format (UTC timezone)
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-shutdownReplace 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:8081Then access via:
curl http://localhost:8081/spinup/example-shutdownRun locally:
make runBuild binary:
make buildhelm uninstall auto-spin-down-operator -n auto-spin-down-operator-systemmake undeploy