Kube-green

Introduction

This guide shows how to enable kube-green on your cluster and configure sleep schedules to automatically scale down workloads during off-hours. For background on what kube-green is and how it works, see the explanation page.

Enabling kube-green

Kube-green is an optional component that is disabled by default. To enable it, add the following to your cluster definition:

kube_green:
  enabled: true

This can be done via a pull request to your cluster definition file, or with the help of a Skyscrapers engineer.

Creating a sleep schedule

Once kube-green is enabled, you can create SleepInfo resources in any namespace to define when workloads should sleep and wake up.

A basic SleepInfo looks like this:

apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: sleep-schedule
  namespace: my-namespace
spec:
  weekdays: "1-5"
  sleepAt: "19:00"
  wakeUpAt: "07:00"
  timeZone: "Europe/Brussels"

Key fields:

  • weekdays: which days the schedule applies. 1 = Monday, 7 = Sunday. Use ranges (1-5) or comma-separated values (1,2,3).
  • sleepAt: time to scale down workloads (HH:MM format)
  • wakeUpAt: time to restore workloads (HH:MM format)
  • timeZone: IANA timezone string (e.g. Europe/Brussels, America/New_York)

Common patterns

Sleep non-production on weeknights

Scale down workloads Monday through Friday outside business hours:

apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: weeknight-sleep
  namespace: staging
spec:
  weekdays: "1-5"
  sleepAt: "19:00"
  wakeUpAt: "07:00"
  timeZone: "Europe/Brussels"

Sleep on weekends

Scale down workloads for the entire weekend:

apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: weekend-sleep
  namespace: staging
spec:
  weekdays: "6-7"
  sleepAt: "00:00"
  timeZone: "Europe/Brussels"

Note

When wakeUpAt is omitted, workloads stay asleep until the next weekday’s wake-up schedule (from a separate SleepInfo) triggers, or until manually scaled back up.

Excluding specific deployments

If certain workloads must remain running during sleep periods (e.g. a message consumer), use excludeRef:

apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: sleep-schedule
  namespace: staging
spec:
  weekdays: "1-5"
  sleepAt: "19:00"
  wakeUpAt: "07:00"
  timeZone: "Europe/Brussels"
  excludeRef:
    - apiVersion: apps/v1
      kind: Deployment
      name: message-consumer

Suspending CronJobs

By default, kube-green only scales Deployments and StatefulSets. To also suspend CronJobs during sleep periods, set suspendCronJobs: true:

apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: sleep-schedule
  namespace: staging
spec:
  weekdays: "1-5"
  sleepAt: "19:00"
  wakeUpAt: "07:00"
  timeZone: "Europe/Brussels"
  suspendCronJobs: true

Verify

After creating a SleepInfo resource, you can verify it was picked up:

kubectl get sleepinfo -n <namespace>

To confirm workloads are being scaled down at the scheduled time, check the kube-green controller logs:

kubectl logs -n kube-green -l app.kubernetes.io/name=kube-green

You can also verify that Deployments in the target namespace have been scaled to 0 replicas:

kubectl get deployments -n <namespace>

Related

Last updated on