Cost saving K8s controller to scale down and up of resources during non-business hours

Overview

Kube-Saver

Motivation

  • Scale down cluster nodes by scaling down Deployments, StatefulSet, CronJob, Hpa during non-business hours and save $$, but if you need to scale back the resources eventhough its a scaledown, don't worry, You will have a Custom Resource which will scale up all resources and wont scale down until next scaledown period.

Installation

  • Install CRD

    kubectl apply -f k8s/crds/crd.yaml
  • Configure your rules in rules.yaml

  • Install kube-saver operator

    kubectl apply -k k8s/

Examples

rules:
  # scale down deployment with name go-app-deployment-2 when current time/day not in uptime
  - id: rules-downscale-deployments
    uptime: Mon-Fri 09:00-17:00 Australia/Sydney
    jmespath: "metadata.name == 'go-app-deployment-2'" 
    resource:
      - Deployment # type of resource
    replicas: 0 # either set the replicas:0 or any number during nonuptime 
  # scale down all deployment, statefulset, cronjob, hpa in namespace kuber when current time/day not in uptime, in this case hpa will be set to 1 as the desired replicas is set as 0
  - id: rules-downscale-all-deployments-in-namespace
    uptime: Mon-Fri 09:00-17:00 Australia/Sydney
    jmespath: "metadata.name == 'kuber'" 
    resource:
      - Namespace # type of resource
    replicas: 0 # either set the replicas:0 or any number during nonuptime 
  # scale down all statefulset in namespace kuber when current time/day not in uptime
  - id: rules-downscale-all-statefulset
    uptime: Mon-Fri 09:00-17:00 Australia/Sydney
    jmespath: "metadata.name == 'statefulset_name'" 
    resource:
      - StatefulSet # type of resource
    replicas: 0 # either set the replicas:0 or any number during nonuptime 
  # disable all cronjob with the labels current time/day not in uptime
  - id: rules-disable-all-cronjob
    uptime: Mon-Fri 09:00-17:00 Australia/Sydney
    jmespath: "metadata.labels.app == 'some_random_app'" 
    resource:
      - cronjob # type of resource
  # set minReplicas of HPA to 1
  - id: rules-set-hpa
    uptime: Mon-Fri 09:00-17:00 Australia/Sydney
    jmespath: "metadata.labels.app == 'some_random_app'" 
    resource:
      - hpa # type of resource
    replicas:1
  # set minReplicas of HPA to 1
  - id: combination-of-resources
    uptime: Mon-Fri 09:00-17:00 Australia/Sydney
    jmespath: "metadata.labels.app == 'some_random_app' || metadata.labels.service != 'some_random_service'" 
    resource:
      - Deployment # type of resource
      - Statefulset
    replicas:0

How can I upscale resouce during the downtime.?

kube-saver will automatically upscale the resoures to orignial number of replicas when the current time falls between the uptime configured in rules.yaml. But if you want to manually scale up single deployment/statefulset or all the deployment & stateulset resources in Namespace, you have following options and it won't be scaled down until next day downtime. Choose any of the option below:

  • Configure upscaled.yaml and

    kubectl apply -f ./k8s/crds/upscaler.yaml
    

    Or

  • Redeploy your deployment.

    Or

  • Edit the uptime in rules.yaml and redeploy the operator

    kubectl apply -k k8s/

Tested

Kubernetes Provider Tested
Google Kubernetes Engine
KIND(no autoscaler)

Note

This project is under development expect changes.

Comments
  • RUSTSEC-2021-0139: ansi_term is Unmaintained

    RUSTSEC-2021-0139: ansi_term is Unmaintained

    ansi_term is Unmaintained

    | Details | | | ------------------- | ---------------------------------------------- | | Status | unmaintained | | Package | ansi_term | | Version | 0.12.1 | | URL | https://github.com/ogham/rust-ansi-term/issues/72 | | Date | 2021-08-18 |

    The maintainer has adviced this crate is deprecated and will not receive any maintenance.

    The crate does not seem to have much dependencies and may or may not be ok to use as-is.

    Last release seems to have been three years ago.

    Possible Alternative(s)

    The below list has not been vetted in any way and may or may not contain alternatives;

    See advisory page for additional details.

    opened by github-actions[bot] 1
  • Deployments with HPA when scaledown replicas is greater than 0

    Deployments with HPA when scaledown replicas is greater than 0

    Test Scenario: If a deployment has an HPA and min replicas of HPA are greater than 1. Now you scale replicas of the deployment to 1. Now the HPA will scale the deployment back to minReplicas and kube-saver will ignore scaling back to 1 for the second time.

    Proposed solution:

    1. Add HPA as a supported resource in rules.yaml. Make sure you match the .spec.minReplicas of HPA to scaleddown replicas of deployment.
    2. If input resource is Namespace. Need to find HPA in Namespace and accordingly set .spec.minReplicas to input replicas. Make sure this is done before Deployment. You can ignore the situation if the input replicas set is 0.
    opened by maheshrayas 1
  • Support hpa

    Support hpa

    • If a namespace has HPA for a deployment and the resource is Namespace and replicas is set to 0. Then HPA minReplicas is set to 1 and the deployment in the namespace is set to 0
    • Support Upscaler functionality for HPA
    • Added more test

    issue: https://github.com/maheshrayas/kube-saver/issues/6

    opened by maheshrayas 0
  • support plurals for resources

    support plurals for resources

    Support Resource name: deployment, deployments, Deployments statefulset, statefulsets, StatefulSet, StatefulSets, Statefulset, Statefulsets namespace, namespaces, Namespace, Namespaces

    opened by maheshrayas 0
  • downscale of resource concurrently

    downscale of resource concurrently

    use tokio::spawn to execute resources concurrently to other tasks. Currently all the tasks are done in sequence (async)

    https://docs.rs/tokio/latest/tokio/fn.spawn.html

    opened by maheshrayas 0
Releases(v0.7.0)
  • v0.7.0(Sep 15, 2022)

    What's Changed

    • Fix time check by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/24

    Full Changelog: https://github.com/maheshrayas/kube-saver/compare/v0.6.0...v0.7.0

    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Aug 22, 2022)

  • v0.5.0(Jul 30, 2022)

    What's Changed

    • feat: Add logging & update kube-rs to 0.74 by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/21
    • feat: Upscaler resources as array by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/22

    Full Changelog: https://github.com/maheshrayas/kube-saver/compare/v0.4.0...v0.5.0 #

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Jul 11, 2022)

    What's Changed

    • Support hpa by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/18
    • feat: Update readme by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/19
    • fix: Rollback to v1 autoscaling by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/20

    Full Changelog: https://github.com/maheshrayas/kube-saver/compare/v0.3.0...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Jul 6, 2022)

    What's Changed

    • fix: cargo-audit by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/15
    • feat: Update crd by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/13
    • fix: Make replicas as optional to support cronjob by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/16

    Full Changelog: https://github.com/maheshrayas/kube-saver/compare/v0.2.0...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Jul 4, 2022)

    • Scale the cron job up and down using the suspend to true and false: https://github.com/maheshrayas/kube-saver/issues/11
    • Support setting suspend to false using Upscale CustomResource
    • fix: Add more test cases
    • feat: Support plurals for resource and add unit test case: https://github.com/maheshrayas/kube-saver/issues/8
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Jun 24, 2022)

  • v0.0.5(Jun 13, 2022)

  • v0.0.2(Jun 10, 2022)

Owner
Mahesh Rayas
Mahesh Rayas
An uncluttered blackboard, ideal for simple sketches during online meetings

lavagna It's a blackboard, not a lasagna. Lavagna is a "no frills" blackboard, ideal for simple sketches during online meetings. You have just a black

Alessandro Pezzato 5 Jul 31, 2022
zero runtime cost default arguments in rust

Default Arguments in Rust Enables default arguments in rust by macro in zero cost. Just wrap function with default_args! and macro with name of functi

Jaeyong Sung 73 Sep 6, 2022
Brutally simple command line app for jotting things down

jot Brutally simple command line app for jotting things down. About jot lets you get things down before you forget, without fiddling folders, naming,

Alexander Alexandrov 1 Apr 8, 2022
Curated list of awesome projects and resources related to Rust and computer security

Awesome Rust Security Curated list of awesome projects and resources related to Rust and computer security Table of Contents Tools Web and Cloud Secur

Alan 88 Sep 21, 2022
Codemod - Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention

Codemod - Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention. Codemod was developed at Facebook and released as open source.

Meta Archive 4k Sep 13, 2022
An open source, programmed in rust, privacy focused tool for reading programming resources (like stackoverflow) fast, efficient and asynchronous from the terminal.

Falion An open source, programmed in rust, privacy focused tool for reading programming resources (like StackOverFlow) fast, efficient and asynchronou

Obscurely 17 Jun 17, 2022
Non-interactive nREPL client for shell scripts and command-line

nreplops-tool (nr) nreplops-tool (nr) is a non-interactive nREPL client designed to be used in shell scripts and on the command-line. Early α warning:

Matti Hänninen 3 Jul 1, 2022
Non-Recursive Inverting of Binary Tree in Rust

Non-Recursive Inverting of Binary Tree in Rust The idea is to implement the classical Inverting of Binary Tree but without using recursion. Quick Star

Tsoding 14 Jul 5, 2022
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp 7.8k Sep 28, 2022
This is a simple lnd poller and web front-end to see and read boosts and boostagrams.

Helipad This package will poll a Lightning LND node for invoices related to Podcasting 2.0 and display them in a web interface. It's intended for use

Podcastindex.org 23 Jul 4, 2022
Execution of and interaction with external processes and pipelines

subprocess The subprocess library provides facilities for execution of and interaction with external processes and pipelines, inspired by Python's sub

Hrvoje Nikšić 358 Sep 21, 2022
create and test the style and formatting of text in your terminal applications

description: create and test the style and formatting of text in your terminal applications docs: https://docs.rs/termstyle termstyle is a library tha

Rett Berg 18 Jul 3, 2021
Command-Line program that takes images and produces the copy of the image with a thin frame and palette made of the 10 most frequent colors.

paleatra v.0.0.1 Command-Line program that takes an image and produces the copy of the image with a thin frame and palette made of the 10 most frequen

Beka Modebadze 22 Jul 27, 2022
This is choose, a human-friendly and fast alternative to cut and (sometimes) awk

Choose This is choose, a human-friendly and fast alternative to cut and (sometimes) awk Features terse field selection syntax similar to Python's list

Ryan Geary 1.3k Sep 21, 2022
Cold Clear 2 is a modern Tetris versus bot and a complete rewrite and evolution of Cold Clear.

Cold Clear 2 Cold Clear 2 is a modern Tetris versus bot and a complete rewrite and evolution of Cold Clear. It implements the Tetris Bot Protocol for

Mark Carlson 24 Aug 25, 2022
Devops kafka like ls, tail, head,and echo with kls, ktail, khead and kecho

Kafka CLI Tools DevOps topics of Message Queue(eg kafka, pulsar, rabbitmq) like ls, echo, head and tail with kls, kecho, khead and ktail Getting Start

imotai 4 Dec 31, 2021
A blazingly fast Insertion Sort and Quick Sort visualizer built with Rust and WASM.

sortysort A blazingly fast Insertion Sort and Quick Sort visualizer built with Rust and WASM. Try it in your browser from here Testing locally cargo r

null 3 Jan 28, 2022
Sample and plot power consumption, average frequency and cpu die temperatures over time.

sense Sense is a small tool to gather data on cpu temperature, power usage and clock frequency and plot graphs during some load. Dependencies Sense is

Luuk van der Duim 5 Jan 21, 2022