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
  • RUSTSEC-2022-0059: Using a Custom Cipher with `NID_undef` may lead to NULL encryption

    RUSTSEC-2022-0059: Using a Custom Cipher with `NID_undef` may lead to NULL encryption

    Using a Custom Cipher with NID_undef may lead to NULL encryption

    | Details | | | ------------------- | ---------------------------------------------- | | Package | openssl-src | | Version | 300.0.9+3.0.5 | | URL | https://www.openssl.org/news/secadv/20221011.txt | | Date | 2022-10-11 | | Patched versions | >=300.0.10 | | Unaffected versions | <300.0.0 |

    OpenSSL supports creating a custom cipher via the legacy EVP_CIPHER_meth_new() function and associated function calls. This function was deprecated in OpenSSL 3.0 and application authors are instead encouraged to use the new provider mechanism in order to implement custom ciphers.

    OpenSSL versions 3.0.0 to 3.0.5 incorrectly handle legacy custom ciphers passed to the EVP_EncryptInit_ex2(), EVP_DecryptInit_ex2() and EVP_CipherInit_ex2() functions (as well as other similarly named encryption and decryption initialisation functions). Instead of using the custom cipher directly it incorrectly tries to fetch an equivalent cipher from the available providers. An equivalent cipher is found based on the NID passed to EVP_CIPHER_meth_new(). This NID is supposed to represent the unique NID for a given cipher. However it is possible for an application to incorrectly pass NID_undef as this value in the call to EVP_CIPHER_meth_new(). When NID_undef is used in this way the OpenSSL encryption/decryption initialisation function will match the NULL cipher as being equivalent and will fetch this from the available providers. This will succeed if the default provider has been loaded (or if a third party provider has been loaded that offers this cipher). Using the NULL cipher means that the plaintext is emitted as the ciphertext.

    Applications are only affected by this issue if they call EVP_CIPHER_meth_new() using NID_undef and subsequently use it in a call to an encryption/decryption initialisation function. Applications that only use SSL/TLS are not impacted by this issue.

    See advisory page for additional details.

    opened by github-actions[bot] 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.8.0)
  • v0.8.0(Oct 16, 2022)

    What's Changed

    • Alert on scaledown by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/26
    • add documentation docs by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/27
    • examples for slack alert by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/28
    • fix by @maheshrayas in https://github.com/maheshrayas/kube-saver/pull/29

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

    Source code(tar.gz)
    Source code(zip)
  • 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
Crunch is a command-line interface (CLI) to claim staking rewards every X hours for Substrate-based chains

crunch · crunch is a command-line interface (CLI) to claim staking rewards every X hours for Substrate-based chains. Why use crunch To automate payout

null 39 Dec 8, 2022
💾Saving Your Hard Disk, One Project at a Time

nodemore ?? Nodemore Recursively Searches Directories for Unused Projects Contents Why? Installation Usage Configuration Why? NodeJS has a horrible wa

Will 13 Apr 16, 2023
Automate your business flows, support, change tickets with Automatdeck

Automatdeck agent Website: https://automatdeck.com Documentation: https://doc.automatdeck.com Automatdeck agent is a simple lightweight IT automation

Kheshav Sewnundun 5 Aug 2, 2022
Rust based Kubernetes Operator to deploy K8s objects minimally.

kube-nimble nimble /ˈnɪmbl/ - quick and light in movement or action; agile. This project began from a place of curiosity about Kubernetes CRDs and the

Meet Vasani 3 Feb 26, 2024
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
Projects worked on during Juno Code and Chill sessions.

Juno Code and Chill projects These projects are created during Juno "Code and Chill" session in the Juno discord. Project Description cw721-piggy-bank

Junø 6 May 2, 2023
A comprehensive collection of resources and learning materials for Rust programming, empowering developers to explore and master the modern, safe, and blazingly fast language.

?? Awesome Rust Lang ⛰️ Project Description : Welcome to the Awesome Rust Lang repository! This is a comprehensive collection of resources for Rust, a

Shubham Raj 16 May 29, 2023
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 6 Dec 15, 2022
auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.

Auto Rust auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, util

Minsky 6 May 14, 2023
Kill processes protected by antivirus during offensive activities.

superman Kill everything. usage Options: -p, --pid <PID> Pid to kill -r Recursive kill process -t, --time <TIME> Kill interv

B1-TEAM 96 Jun 16, 2023
Neovim plugin for moving lines up and down, written in Rust

Moveline.nvim Moveline is a simple plugin for moving lines up and down. It's written in Rust using my library nvim-utils. Installation Moveline can be

Will Hopkins 34 Mar 18, 2023
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 131 Jan 1, 2023
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
A language parser tool to build recursive descent top down parser.

lang-pt A language parser tool to generate recursive descent top down parser. Overview Parsers written for the languages like Javascript are often cus

Creative Forest 7 Jan 4, 2023
A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies, or candies!

Mythmellow A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies

Umut 3 Oct 16, 2023
A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies, or candies!

Mythmallow A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies

Umut 3 Oct 29, 2023
Provides a cross platform way to shut down, reboot or log out operations

@napi-rs/system-shutdown This package provides a cross platform way to shut down, reboot or log out operations. Supported platforms: Linux, Windows an

LongYinan 7 Nov 2, 2023
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 Dec 20, 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 Dec 29, 2022