custom-pod-autoscaler

module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2021 License: Apache-2.0

README

Build codecov go.dev Go Report Card Documentation Status License

This project is supported by:

Custom Pod Autoscaler

This is the Custom Pod Autoscaler (CPA) code and base images.

What is it?

A Custom Pod Autoscaler is a Kubernetes autoscaler that is customised and user created. Custom Pod Autoscalers are designed to be similar to the Kubernetes Horizontal Pod Autoscaler. The Custom Pod Autoscaler framework allows easier and faster development of Kubernetes autoscalers. 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.

How does it work?

A Custom Pod Autoscaler has a base program (defined in this repository) that handles interacting with user logic, for example by using shell commands and piping data into them. 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 base 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.

Developing this project

Environment

Developing this project requires these dependencies:

To view the docs, you need Python 3 installed:

To view docs locally you need some Python dependencies, run:

pip install -r docs/requirements.txt

It is recommended to test locally using a local Kubernetes managment system, such as k3d (allows running a small Kubernetes cluster locally using Docker).

Once you have a cluster available, you should install the Custom Pod Autoscaler Operator (CPAO) onto the cluster to let you install Custom Pod Autoscalers.

With the CPAO installed you can install your development builds of the CPA onto the cluster by building the image locally, and then build CPAs using the new development image.

Finally you can build a CPA example (see the example/ directory for choices), and then push the image to the K8s cluster's registry (to do that with k3d you can use the k3d image import command). Once the autoscaler's image is available in the registry it can be deployed using kubectl.

Commands
  • make - builds the CPA binary.
  • make docker - builds the CPA base images.
  • make lint - lints the code.
  • make beautify - beautifies the code, must be run to pass the CI.
  • make unittest - runs the unit tests.
  • make vendor - generates a vendor folder.
  • make doc - hosts the documentation locally, at 127.0.0.1:8000.
  • make view_coverage - opens up any generated coverage reports in the browser.

Directories

Path Synopsis
api
v1
Package v1 provides routing and endpoints for the Custom Pod Autoscaler HTTP REST API version 1.
Package v1 provides routing and endpoints for the Custom Pod Autoscaler HTTP REST API version 1.
Package autoscaler provides methods for scaling a resource - by triggering metric gathering, feeding these metrics to an evaluation and using this evaluation to scale the resource.
Package autoscaler provides methods for scaling a resource - by triggering metric gathering, feeding these metrics to an evaluation and using this evaluation to scale the resource.
cmd
custom-pod-autoscaler
Custom Pod Autoscaler is the core program that runs inside a Custom Pod Autoscaler Image.
Custom Pod Autoscaler is the core program that runs inside a Custom Pod Autoscaler Image.
Package config handles parsing YAML and environment variable input into a Custom Pod Autoscaler configuration file.
Package config handles parsing YAML and environment variable input into a Custom Pod Autoscaler configuration file.
Package evaluate provides functionality for managing evaluating, calling external evaluation logic through shell commands with relevant data piped to them.
Package evaluate provides functionality for managing evaluating, calling external evaluation logic through shell commands with relevant data piped to them.
example
Package execute abstracts methods, providing a standardised way to trigger methods and provide values
Package execute abstracts methods, providing a standardised way to trigger methods and provide values
http
Package http handles interactions over HTTP
Package http handles interactions over HTTP
shell
Package shell handles interactions with the OS shell
Package shell handles interactions with the OS shell
Package fake provides stubs for testing relevant to the Custom Pod Autoscaler packages
Package fake provides stubs for testing relevant to the Custom Pod Autoscaler packages
internal
measure
Package measure provides functionality for measuring/retrieving metrics from the K8s metrics server.
Package measure provides functionality for measuring/retrieving metrics from the K8s metrics server.
measure/value
Package value represents a computed value for a metric, can be either a raw value or an average value
Package value represents a computed value for a metric, can be either a raw value or an average value
podclient
Package podclient provides an on-demand client for retrieving pods, without using caching, as the HorizontalPodAutoscaler does.
Package podclient provides an on-demand client for retrieving pods, without using caching, as the HorizontalPodAutoscaler does.
Package metric provides functionality for managing gathering metrics, calling external metric gathering logic through shell commands with relevant data piped to them.
Package metric provides functionality for managing gathering metrics, calling external metric gathering logic through shell commands with relevant data piped to them.
Package scale abstracts interactions with the Kubernetes scale API, providing a consistent way to scale resources that are supported by the Custom Pod Autoscaler.
Package scale abstracts interactions with the Kubernetes scale API, providing a consistent way to scale resources that are supported by the Custom Pod Autoscaler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL