Back to blog
Published
2026-11-13
Reading time
5 min
Tags
FinOps
Kubernetes
kube-green
CostOptimization
GreenOps

Turn off test environments when nobody uses them: kube-green in practice

Development, staging and QA environments are usually a smaller copy of production that runs 24 hours a day, 7 days a week. But the team only works on them during working hours. The rest of the time, nights and weekends, is pure cost.

The quick maths

A week has 168 hours. If the team works Monday to Friday from 8:00 to 20:00 (already generous), the environment is used for 60 hours. The other 108 hours, 64% of the time, are waste.

Take a staging cluster on AWS with 3 m6i.large nodes (about $0.107/h on-demand in eu-west-1):

Approx. monthly cost
3 nodes running 24/7 ~$235
Turning off 2 of the 3 nodes out of hours ~$135
Savings ~$100/month (43%)

We count 2 nodes, not 3, because realistically one node always stays up for system pods (CoreDNS, the operator itself, DaemonSets…). Multiply that by the number of environments (dev, staging, QA, one per feature branch…) and the figure starts to get serious.

What kube-green is

kube-green is an open-source Kubernetes operator (MIT licence) that does exactly this: it puts a namespace's resources to sleep on one schedule and wakes them up on another. You configure it with its own resource, SleepInfo, one per namespace.

When it is time to sleep:

  • Deployments and StatefulSets are scaled to 0 replicas.
  • CronJobs are suspended (optional, if you turn it on).
  • The original replica counts are saved in a Secret in the same namespace, named after the SleepInfo.

At wake-up time, it restores everything as it was.

Installation

kube-green uses webhooks, which need certificates. The recommended way is to have cert-manager installed in the cluster. Then, with Helm:

helm repo add kube-green https://kube-green.github.io/helm-charts/
helm install kube-green kube-green/kube-green \
  --namespace kube-green --create-namespace

You can also install it with a kubectl apply of the release manifest, or from OperatorHub.

Your first SleepInfo

This is all the YAML you need to turn off the staging namespace out of hours:

apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: working-hours
  namespace: staging
spec:
  weekdays: "1-5"          # Monday to Friday
  sleepAt: "20:00"
  wakeUpAt: "07:45"
  timeZone: "Europe/London"
  suspendCronJobs: true

It shuts down on Friday at 20:00 and does not come back until Monday at 7:45: the weekend is covered with nothing else to do.

Note that it wakes up at 7:45, not 8:00. If the nodes have been turned off too (and they should be, more on that below), the cluster has to bring up new machines before the pods can start, and that takes a few minutes.

Excluding what must stay on

If something has to stay up (a database that takes ages to start, a gateway other teams depend on), exclude it:

spec:
  # ...
  excludeRef:
    - apiVersion: "apps/v1"
      kind: Deployment
      name: api-gateway

You can also match by labels with matchLabels, or the other way round: use includeRef to turn off only what matches. For resources that are not Deployments, StatefulSets or CronJobs, kube-green accepts patches (JSON patches applied at sleep and reverted at wake-up), with the matching RBAC permissions.

Where the savings get lost (and how to avoid it)

This is where most guides stop, and it is where the important part is. Scaling pods to zero saves nothing on its own. You pay for nodes, disks and load balancers, not pods.

1. No node autoscaling, no savings

If the node group has a fixed size, the nodes stay up, empty, and the bill is identical. The cluster needs to be able to remove underused nodes: Cluster Autoscaler or Karpenter on AWS, or your managed provider's node pool autoscaling. Check the node group's minimum size too: if the minimum is 3, it will never go below 3.

2. GitOps will turn the pods back on

If you use Argo CD with selfHeal, it will see that the replicas no longer match Git and put them back within minutes. Tell it to ignore that field:

spec:
  ignoreDifferences:
    - group: apps
      kind: Deployment
      jsonPointers: ["/spec/replicas"]
    - group: apps
      kind: StatefulSet
      jsonPointers: ["/spec/replicas"]
  syncPolicy:
    syncOptions:
      - RespectIgnoreDifferences=true

The same goes for Flux: it must not overwrite replicas.

3. What is not a pod keeps costing

  • Persistent volumes (EBS, disks) stay, and you keep paying for them. That is what you want (no data loss), but count it.
  • Every Service of type LoadBalancer keeps its load balancer running. If staging has one per service, consider routing them all through a single Ingress.
  • Managed services outside the cluster (RDS, ElastiCache, OpenSearch…) are not touched. Those need another tool, such as AWS Instance Scheduler or a scheduled job that stops them.

4. Check the bill, not the cluster

Pods at zero does not mean you pay less. Look at the hourly cost of that cluster's nodes before and after: at night and at weekends the curve should drop. If it does not, one of the points above is failing.

In short

  1. Work out how many hours a week each non-production environment is really used.
  2. Install kube-green and create one SleepInfo per namespace with that schedule.
  3. Make sure the nodes can scale down and that GitOps does not undo what kube-green does.
  4. Review what is left out: disks, load balancers and managed databases.
  5. Validate the savings on the bill.

It is one of the best effort-to-return optimisations you can make on a cluster: one YAML per namespace, and the savings arrive every night.

Find this waste automatically

PruneOps audits your cloud accounts and tells you what to fix first.

Get started Read the docs