Skip to content

Package kta_python_sdk.core

core package.

This package contains

  • interfaces to implement custom autoscaling algorithms
  • backends to run custom and the provided ready-to-use autoscaling algorithms

backend

Backends make autoscaling algorithms accessible to the Kubernetes Operator.

  • Backends decouple the interprocess communication logic from the implementation logic of the autoscaling algorithms.
  • Backends are agnostic to the autoscaling algorithm.

BackendProtocol

Bases: Protocol

Internal Protocol for backends. Methods of this Protocol must not be invoked by the user.

run()

Runs the backend with the set autoscaling algorithm.

Returns: None

set_up(value)

Sets the autoscaling algorithm for a backend.

Parameters:

Name Type Description Default
value AutoscalingAlgorithmUDFUnion

The autoscaling algorithm.

required

Returns: None

HTTPBackend

HTTPBackend.

Exposes an autoscaling algorithm via HTTP using FastAPI and the uvicorn webserver. This backend requires the installation of the following extras: http-backend.

unwrap_autoscaling_algorithm property

Visible for testing.

__init__(**uvicorn_kwargs)

Initializes a new instance.

Parameters:

Name Type Description Default
**uvicorn_kwargs Any

Arguments passed to uvicorn.run().

{}

run()

Runs the backend with the set autoscaling algorithm UDF(s).

set_up(value)

Sets up the backend.

bootstrap

Functions for application bootstrapping.

run(autoscaling_algorithm, backend)

Entry point.

Parameters:

Name Type Description Default
autoscaling_algorithm AutoscalingAlgorithmUDFUnion

The autoscaling algorithm.

required
backend BackendProtocol

The backend.

required

Returns: None

udf

Interfaces to implement autoscaling algorithms via stateless user-defined functions (UDFs).

Autoscaling algorithms consist of up to 3 steps as part of the MAPE-K loop: Monitor, Analyze (optional), Plan. The Execute and Knowledge step are handled by the Kubernetes Operator, Each of algorithm step (Monitor, Analyze, Plan) maps to exactly one UDF. We provide individual interfaces for each step as well as a combined interface.

Implementing steps with individual interfaces is useful in cases where at least one UDF

  • requires specialized hardware (e.g., a GPU for algorithms that use deep learning models) and should be scheduled on a specific node.
  • should run in a separate pod (for any reason).
  • needs resources that cannot be accessed from inside the cluster.
  • should serve multiple clusters and is deployed in a central environment.

AutoscalingAlgorithmUDFUnion = Union[AutoscalingAlgorithmMonitorUDF, AutoscalingAlgorithmAnalyzeUDF, AutoscalingAlgorithmPlanUDF, AutoscalingAlgorithmUDFs] module-attribute

AutoscalingAlgorithmAnalyzeUDF

Bases: AutoscalingAlgorithmUDFMeta

Interface for the analyze step of the MAPE-K loop.

__init__(*args, **kwargs)

analyze(ctx) abstractmethod

The analyze step.

Parameters:

Name Type Description Default
ctx Context[MONITOR, ANALYZE, PLAN]

Current MAPE-K evaluation loop context.

required

Returns: Result of the analyze step or None

AutoscalingAlgorithmMonitorUDF

Bases: AutoscalingAlgorithmUDFMeta

Interface for the monitor step of the MAPE-K loop.

__init__(*args, **kwargs)

monitor(ctx) abstractmethod

The monitor step.

Parameters:

Name Type Description Default
ctx Context[MONITOR, ANALYZE, PLAN]

Current MAPE-K evaluation loop context.

required

Returns: Result of the monitor step.

AutoscalingAlgorithmPlanUDF

Bases: AutoscalingAlgorithmUDFMeta

Interface for the plan step of the MAPE-K loop.

__init__(*args, **kwargs)

plan(ctx) abstractmethod

The plan step.

Parameters:

Name Type Description Default
ctx Context[MONITOR, ANALYZE, PLAN]

Current MAPE-K evaluation loop context.

required

Returns: Result of the plan step.

AutoscalingAlgorithmUDFMeta

Bases: ABC

Base class for all autoscaling algorithm UDFs.

Subtypes of this class may only contain attributes, regular methods and the call method (but no other 'dunder' methods). All methods in the class (except init) have to be stateless.

Warning

It is the responsibility of the user implementing the UDFs to ensure statelessness. However, provided backends will check if the implemented functions are stateless in a best effort manner.

AutoscalingAlgorithmUDFs

Bases: AutoscalingAlgorithmMonitorUDF[MONITOR, ANALYZE, PLAN], AutoscalingAlgorithmAnalyzeUDF[MONITOR, ANALYZE, PLAN], AutoscalingAlgorithmPlanUDF[MONITOR, ANALYZE, PLAN], AutoscalingAlgorithmUDFMeta, ABC

Combined interface for all steps (monitor, analyze, plan) of the MAPE-K loop.