rekuberate-io/sleepcycles: An automated way to reclaim your unused Kubernetes resources

Akriotis Kyriakos
7 min readJun 26, 2023

Define sleep & wake up cycles for your Deployments, CronJobs, StatefulSets and HorizontalPodAutoscalers.

TL;DR: Define sleep & wake up cycles for your Kubernetes resources. Automatically schedule to shutdown Deployments, CronJobs, StatefulSets and HorizontalPodAutoscalers that occupy resources in your cluster and wake them up only when you need them, reducing that way the overall power consumption and eventually your carbon emissions footprint.

Introduction

In today’s world of cloud-native applications and dynamic workloads, efficient resource management is key. Kubernetes has revolutionized container orchestration, but managing the power consumption of resources within a cluster can still pose challenges. This is where rekuberate-io/sleepcycles comes into play, offering a powerful solution to optimise power consumption by defining sleep and wake-up cycles for Kubernetes resources.

Playing with the words Kubernetes and recuperate, the word rekuberate was born. As defined in Merriam-Webster dictionary, recuperate means:

1.- to get back : REGAIN

2.- to bring back into use or currency : REVIVE

Nowadays, is predominantly used as term in automotive industry where recuperationconverts kinetic energy during braking into electrical energy. This leads to a significant increase in range — and since most of the braking energy is not passed on to the braking units, their wear is also reduced.”, excerpt taken from the official Volkswagen UK webpage explaining how Brake energy recuperation works in electric cars.

In that very sense rekuberate-io/sleepcycles, is an innovative Kubernetes custom Controller that introduces a unique yet rather simple approach to reclaim back unused resources and to manage power consumption in Kubernetes clusters in specific pre-scheduled time windows. By automatically scheduling the shutdown of Deployments, CronJobs, StatefulSets, and HorizontalPodAutoscalers that occupy resources, it helps reduce overall power consumption. These resources are put to sleep, conserving energy when they are not actively needed, and are awakened only when required.

The benefits of using rekuberate-io/sleepcycles in a Kubernetes environment are significant. Let’s explore some of them:

1. Efficient Resource Management: It enables efficient management of resources in a Kubernetes cluster. By scheduling shutdowns during periods of low demand or inactivity, it minimizes the consumption of computing resources. This not only reduces energy usage but also optimizes resource allocation, allowing for better utilization of the cluster.

2. Cost Savings: By reducing power consumption, it helps organizations save on operational costs. Lower energy consumption means reduced electricity bills, especially for large-scale deployments or cloud-based infrastructure. It allows businesses to adopt an environmentally friendly approach while also achieving cost savings.

3. Environmental Sustainability: With the increasing emphasis on sustainability, it can play a crucial role in minimizing the carbon footprint of Kubernetes clusters. By reducing power consumption during idle periods, it contributes to environmental conservation and promotes green computing practices.

4. Seamless Resource Activation: It ensures that resources are awakened only when they are needed, avoiding unnecessary resource usage. When demand increases or specific events occur, the controller will automatically wake up the required resources, allowing applications to scale and perform optimally without any manual intervention.

5. Customizable Sleep and Wake-Up Cycles: It provides the flexibility to define sleep and wake-up cycles based on specific business needs. Organizations can tailor the schedules to match expected patterns of demand and optimize resource availability accordingly. This customization empowers users to align resource utilization with their unique requirements.

In conclusion, rekuberate-io/sleepcycles, with its ability to define sleep and wake-up cycles for Kubernetes resources, offers an effective solution for optimizing power consumption in clusters. By automatically scheduling shutdowns during idle periods, it reduces overall energy usage and contributes to cost savings, environmental sustainability, and efficient resource management empowering in that way companies to take better control of their Kubernetes environments and achieve a more sustainable and cost-effective infrastructure.

How it works

You’ll need a Kubernetes cluster to run against. You can use KIND or K3D to get a local cluster for testing, or run against a remote cluster. If you don’t have one in place you can follow this guide and get a K3S cluster in a matter of less than a minute:

rekuberate-io/sleepcycles introduces a new Custom Resource called SleepCycle. Under config/samples you will find an example manifest that you can use to test this controller:

apiVersion: core.rekuberate.io/v1alpha1
kind: SleepCycle
metadata:
name: sleepcycle-sample
spec:
shutdown: "0 20 * * *"
wakeup: "30 7 * * 1-5"
enabled: true

You need to provide to every SleepCycle the shutdown (mandatory) and wakeup (non-mandatory) policies via Cron expressions (do not include seconds). The example above will set a SleepCycle schedule shutting down your workloads every day at 20:00 UTC and waking them up every weekday at 07:30 UTC.

SleepCycle is a Namespaced Custom Resource, and the controller will monitor all the resources in the Namespace you installed the SleepCycle manifest and they are decorated with a Label that has as key rekuberate.io/sleepcycle and as value the name of the manifest you created:

apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-demo
rekuberate.io/sleepcycle: sleepcycle-sample
name: nginx-demo
namespace: default
spec:
...
...

Combining those two attributes (shutdown & wakeup) you can fully automate the sleep cycles of your clusters workloads. For instance, you can put your development resources to sleep in non-office hours or weekends and wake them up again in the morning or on Monday, or turn-on resources during specific events and after that put them back in hibernation. Doing that you can reclaim valuable CPU and memory resources and redistribute them to other workloads in your cluster but moreover is a very efficient & easy way to reduce power consumption.

Benefits

Reducing energy consumption in Kubernetes is extremely important due to the following reasons:

1. Environmental Impact: The IT industry has a significant carbon footprint, and data centers, including those hosting Kubernetes clusters, contribute to greenhouse gas emissions. By reducing energy consumption in Kubernetes, organizations can actively contribute to mitigating climate change and promoting environmental sustainability. Minimizing power usage helps decrease the reliance on fossil fuels and lowers the carbon emissions associated with electricity generation.

2. Cost Efficiency: Energy costs constitute a substantial portion of operational expenses for organizations running Kubernetes clusters. By reducing energy consumption, businesses can achieve significant cost savings in terms of electricity bills. Optimizing resource utilization and adopting energy-efficient practices not only benefits the environment but also contributes to financial efficiency and improved profitability.

3. Scalability and Capacity Planning: Kubernetes provides an elastic infrastructure, allowing applications to scale up and down based on demand. However, without effective management of power consumption, scaling resources can lead to unnecessary energy usage. By implementing strategies to reduce energy consumption, organizations can align power usage with actual workload requirements, ensuring optimal resource allocation and capacity planning.

4. Resource Utilization: Kubernetes clusters often comprise a large number of nodes and containers, which consume power even during periods of low or no activity. By implementing sleep and wake-up cycles with rekuberate-io/sleepcycles, organizations can maximize resource utilization and avoid wasting energy on idle resources. This ensures that energy is allocated to active workloads and applications, promoting operational efficiency.

5. Corporate Social Responsibility: Many businesses recognize the importance of corporate social responsibility (CSR) and strive to operate in an environmentally conscious manner. Taking steps to reduce energy consumption in Kubernetes aligns with CSR initiatives and demonstrates a commitment to sustainable practices. It enhances the organization’s reputation, attracts environmentally conscious customers, and can positively impact brand perception.

6. Regulatory Compliance: Energy efficiency regulations and guidelines are becoming increasingly stringent across industries. By actively managing and reducing energy consumption in Kubernetes, organizations can ensure compliance with relevant energy efficiency standards and regulations. This helps avoid penalties, legal complications, and reputational risks associated with non-compliance.

7. Long-Term Sustainability: Kubernetes clusters are intended to operate continuously over extended periods. By adopting energy-efficient practices, organisations can extend the lifespan of hardware components and reduce the need for frequent replacements. This not only conserves resources but also contributes to the long-term sustainability of the infrastructure.

In summary, reducing energy consumption in Kubernetes is crucial for environmental preservation, cost efficiency, scalability, resource utilization, corporate social responsibility, regulatory compliance, and long-term sustainability. By implementing strategies to optimize power usage, organisations can contribute to a greener future while enjoying financial benefits and operational efficiency.

Future work

One feature that is coming in the near future in rekuberate-io/sleepcycles, is the decommissioning of workloads on a scheduled-basis. Let’s say you need a development environment for developing and testing new features of your product. In self-service Kubernetes environments is not uncommon we — developers — to leave a mess behind after the project is over. Nobody is taking care to decommission all those workloads not needed anymore and they end up lingering there and consuming resources & capacity that could be used somewhere else.

Yet another project is on rails, rekuberate-io/carbon, a Kubernetes tool that will measure and attribute the power consumed by every individual Pod and combine them with the corresponding carbon intensity coefficient of your DC at the period of measurement in order to calculate the actual CO2 emission footprint of your workloads. Transforming your workloads and consequently Kubernetes to a carbon-aware platform and shift your resources demand by aiming to minimize your emissions footprint will be of paramount importance in the years to come.

If you found this information useful, don’t forget to 👏 under this article and feel free to contribute to rekuberate-io/sleepcycles with features or functionallity that fit your needs, it is open source after all.

Stay tuned…

--

--

Akriotis Kyriakos

talking about: kubernetes, golang, open telekom cloud, aws, openstack, sustainability, software carbon emissions