Kube-green Operator…

Kamlesh Prajapati
4 min readJul 11, 2023

In app modernization era, managing resource utilization is very essential to contain the costs and limit energy consumption. kube-green is a Kubernetes operator that allows to shut down environments or specific resources in order to optimize resource utilization, limiting energy waste.

What is an Operator?
An operator is a Kubernetes-native application that extends the capabilities of the Kubernetes controller concept. It consists of three components:

  1. Controller
  2. Custom resource and
  3. Application Knowledge

​​​​​Operators are responsible for managing the application lifecycle and can be configured to oversee all aspects of it. While all operators are controllers, not all controllers are operators.
Operators are ideal for handling stateful applications that require ongoing maintenance.

What is the kube-green operator?
The kube-green operator is an operator that helps reduce the CO2 footprint of your Kubernetes clusters. It is a Kubernetes add-on that automatically shuts down and starts up some of your resources at designated times when you don’t need them. It suspends resources during off-hours to help reduce CO2 emissions.

The resources currently supported are: -

  1. Deployments and
  2. CronJobs.

What are the benefits and use cases for the kube-green operator?
In a cluster, non-production namespaces are usually used only during business hours.
The business hours are around 40 hours per week, respect the total number of weekly hours which are 168.
Also, in Kubernetes the resources could be allocated (both CPU and memory, setting the request of a container) also if not used. This means most of the time the pods in these namespaces are unnecessarily consuming resources.

The basic idea of kube-green is to stop all pods in those namespaces.​​​​​​​

How it is possible?

kube-green is a Kubernetes controller, which define a Custom Resource Definition called SleepInfo. SleepInfo CRD define when to stop and restart the pods in a namespace.

So, for example in development namespaces, it is possible to stop all the pods in non-business hours: wake up every morning from Monday to Friday and stop every night from Monday to friday.

An example of SleepInfo CRD to make it is:

Installing kube-green operator on OpenShift

Step 1: Install the kube-green operator on OpenShift

  • Search for kube-green in Operators > OperatorHub in the OpenShift Container Platform Console.
  • Install the kube-green operator. (Note: kube-green is only available as an all-namespaces operator in the openshift-operators namespace and cannot be installed in specific namespaces.)

Step 2: Configure a new instance of SleepInfo

  • Configure an instance of SleepInfo with the correct namespace, suspended resource type, timezone, wake and sleep times, and designated days (see the image below).
  • Once everything is as it should be, create your SleepInfo instance and watch as it manages and shuts down or spins up your Deployments at the designated time intervals.

SleepInfo can easily be adjusted accordingly to your needs and schedule. OpenShift makes installing and configuring kube-green quick and fairly simple, making it easy to keep your cluster green and free of unnecessary resource consumption.

Conclusion:
Everything we do online has an impact on the real-world environment.
From the emails in our inboxes to photos and videos on the cloud, from online games to digital currency, all this digital activity run on physical servers that constantly use energy. Kube-green is helping to reducing the usage and energy consumption of our tools, workflows, storage, and resources, we can take important steps toward keeping our work clean and the world green.

Note: This is a community provided Operator. These are Operators which have not been vetted or verified by Red Hat. Community Operators should be used with caution because their stability is unknown. Red Hat provides no support for community Operators.

References:
https://kube-green.dev/docs/getting-started/

--

--

Kamlesh Prajapati

DevOps Practitioner (CKA certified , RHOCP Certified, Azure Certified on az-104,az-400,az-303.)