Giter Club home page Giter Club logo

custom-pod-autoscaler's Introduction

Build go.dev Go Report Card Documentation Status License

This project is supported by:

Custom Pod Autoscaler

Custom Pod Autoscalers (CPAs) are custom Kubernetes autoscalers. This project is part of a framework that lets you quickly and easily build your own CPAs without having to deal with complex Kubernetes interactions using the tools and language of your choice.

What is this project?

This project is part of the Custom Pod Autoscaler Framework (CPAF) which is a set of tools to help you easily build your own CPAs. This project is the core of the CPAF, providing a program which runs inside your CPA to manage Kubernetes interactions and custom user logic interactions.

A Custom Pod Autoscaler can be created by using this project, extending the Docker base images provided and inserting your own logic; see the examples for more information.

Features

  • Supports any language, environment and framework; the only requirement is it must be startable by a shell command or HTTP request.
  • Supports all configuration options of the Horizontal Pod Autoscaler (downscale stabilisation, sync period etc.)
  • Allows fast and easy prototyping and development.
  • Abstracts away all complicated Kubernetes API interactions.
  • Exposes a HTTP REST API for integration with wider systems/manual intervention.
  • Can write autoscalers with limited Kubernetes API or lifecycle knowledge.
  • Configuration at build time or deploy time.
  • Allows scaling to and from zero.
  • Can be configured without master node access, can be configured on managed providers such as EKS or GKE.
  • Supports Kubernetes metrics that the Horizontal Pod Autoscaler uses, can be configured using a similar syntax and used in custom scaling decisions.
  • Supports Argo Rollouts.

Why would I use it?

Kubernetes provides the Horizontal Pod Autoscaler, which allows automatic scaling of the number of replicas in a resource (Deployment, ReplicationController, ReplicaSet, StatefulSet) based on metrics that you feed it. Mostly the metrics used are CPU/memory load, which is sufficient for most applications. You can specify custom metrics to feed into it through the metrics API also.

The limitation in the Horizontal Pod Autoscaler is that it has a hard-coded algorithm for assessing these metrics:

desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]

If you need more flexibility in your scaling, beyond this algorithm, Horizontal Pod Autoscaler doesn't meet your needs, you need to write your own scaling logic.

How does it work?

This project is a program that abstracts away complex Kubernetes interactions and handles interacting with custom user logic you can provide to determine how the autoscaler should operate.

When developing a Custom Pod Autoscaler you define logic for two stages:

  • Metric gathering - collecting or generating metrics; can be calling metrics APIs, running calculations locally, making HTTP requests.
  • Evaluating metrics - taking these gathered metrics and using them to decide how many replicas a resource should have.

These two pieces of logic are all the custom logic required to build a Custom Pod Autoscaler, the program will handle all Kubernetes API interactions for scaling/retrieving resources.

Getting started

Check out this getting started guide for a quick start for developers.

More information

See the wiki for more information, such as guides and references.

What other projects are in the Custom Pod Autoscaler Framework?

The Custom Pod Autoscaler Operator is the other part of the Custom Pod Autoscaler Framework, it is an operator that handles provisioning Kubernetes resources for your CPA.

Developing this project

See the contribution guidelines.

custom-pod-autoscaler's People

Contributors

dependabot[bot] avatar iroller avatar jthomperoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

custom-pod-autoscaler's Issues

Manual triggering of Custom Pod Autoscaler evaluation

Rather than being triggered just by the timer and at set intervals, the Custom Pod Autoscaler evaluation could be triggered manually, through a REST endpoint.
This would allow users to send an HTTP request to the Custom Pod Autoscaler and start an evaluation immediately, rather than waiting for the interval to expire.

Add start time for scaler

Allow setting up a timing for the scaler to start, for example could provide the time:

0001-01-01 00:00:15 +0000 UTC

This would cause the scaler to start only after the next round 15 seconds. This would be set up with a default of

0001-01-01 00:00:00 +0000 UTC

Which would by default just start at the next full minute/hour/second etc.

Handle no deployments being managed

At the minute if there are no deployments, the /evaluate.py script still seems to be being called, with no metric JSON, causing it to error out. If there are no deployments, the evaluation should be skipped.

Allow different methods to pass data

Would require a change to how the current configuration to support this, e.g. instead of

metric: "shell command"

It should allow you to specify which way to pass data, for shell commands:

metric: 
  type: "pipe"
  pipe: "shell command"

For something like a HTTP request:

metric: 
  type: "http"
  http: 
    method: "GET"
    endpoint: "https://0.0.0.0:5000/metrics"

This would also apply to evaluations, so a more general configuration option to specify a series of different data transfer options would be useful.

Allow specification of how metrics/evaluations should be run

At the minute, the metric is run for every pod in a deployment; however it would be useful if you could run the metric only per deployment, rather than per each pod.

A new configuration option would help this, run-mode, with these options:

  • per-pod - Runs per pod.
  • per-deployment - Runs per deployment.

Use vendor for golint

Running golint pulls down dependencies rather than using the vendor directory, slowing down the CI.

Expose evaluations through an API endpoint

Evaluations should be retrievable through an API endpoint:
GET /evaluations
Returning:

[
  {
    "deployment": "example-deployment",
    "evaluation": {
      "target_replicas": 2
    }
  }
]

This evaluation should be calculated at request time.

Expose metrics through an API endpoint

Metrics should be retrievable through an API endpoint:
GET /metrics
Returning:

[
  {
    "deployment": "example-deployment",
    "metrics": [
      {
        "pod": "example-pod",
        "value": "value"
      }
    ]
  }
]

These metrics should be calculated at request time.

Metric and Evaluation timeout

Implement a timeout for fetching metrics/evaluations, configurable - stops the CPA being unresponsive if a script fails - i.e due to pod terminating/crashing half way through an evaluation.

Support scaling to zero

This code seems to be preventing me from scaling a deployment to zero replicas:

if currentReplicas == 0 {

My use case is a queue-based processing system with a bunch of GPUs, so scale to zero is rather important (and also why I can't use the build in HorizontalPodAutoscaler)

Deploy release images to Docker Hub

If a new release is built on GitHub, it should result in a new image being pushed to Docker Hub and that image should be tagged as latest.

Choose which pods to terminate when scaling down

The CPA evaluator could decide which pods to terminate when scaling down, rather than relying on the Kubernetes decision making which bases it on how old the pod is.
This could be a list of pods with priorities assigned to them, with the lowest priority pods terminated when scaling down as needed.

Cooldown feature

Thrashing is when a deployment is scaled up and down repeatedly in a short period of time, caused by being right on the threshold of an evaluation. For example, if the number of pods in a deployment rapidly changes between 2 and 3 because of small changes in the metrics as it is directly on a boundary/threshold.
The Cooldown feature would allow setting a delay or a cool down period on when to scale, avoiding rapid changes in number of pods for minor changes in the metric being evaluated. For example, a cooldown could be set to not scale again if a deployment has been scaled in the past 5 minutes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.