Categorygithub.com/ryanmt/cluster-resource-autoscaler
repositorypackage
0.0.0-20211108172319-56cfc232aef1
Repository: https://github.com/ryanmt/cluster-resource-autoscaler.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Cluster Resource Autoscaler

Scale something in proportion to the scale of the cluster compute resources. This might make more sense in some cases than pod/node count based scaling as the load carried by a pod or node could be drastically distinct.

MVP

This is currently very much an MVP implementation. Some ideas about how to improve this further or expand the scope are:

  • Support scaling on arbitrary resource types (since those are themselves extensible in the k8s API) rather than just CPU/memory
  • Allow for multiple scaling definitions against a single Target deployment/replicaset/statefulset
  • HA leader election for resiliency of this autoscaler
  • Histeresis in scaling to avoid flapping
  • Support any "Scalable" API entity rather than just deployments, replicasets, and statefulsets.
  • Resolve for maximum among all scaling parameters

Configuring a target for autoscaling

Please mount a configmap containing a valid config.json JSON configuration key into the deployment of this application. CRA will automatically read any changes to the configuration on the next tick of its update loop.

Configuration Schema

See example in test_config.json.

config.json object is an array of individual checks, each of which should specify a particular target for scaling.

[
  {
    "MemoryPerReplica": 100e9,
    "CPUPerReplica": 16,
    "Target": {
      "Name": "scalable-service",
      "Namespace": "default",
      "Type": "deployment"
    }
  }
]
KeyDescription
MemoryPerReplicaThe amount of memory to target for each replica, expressed in bytes
CPUPerReplicaThe number of cores to target for each replica, expressed in cores
Target.NameThe name of the "target" "kind" which should be selected to scale
Target.NamespaceThe namespace of the "target" to scale
Target.TypeThe kind of object which we are scaling. Must be a member of {deployment,replicaset,statefulset}

Deploying

Please see the example in manifests/all.yaml.

ClusterRole

Must provide a ClusterRole which allows:

- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - metrics.k8s.io
  resources:
  - nodes
  verbs:
  - get
  - list
- apiGroups:
  - apps
  resources:
  - deployments/scale
  - replicasets/scale
  - statefulsets/scale
  verbs:
  - get
  - update

Node permissions are required to determine how much cluster compute is available

Metric permissions are only now required for debugging logging statements and will be removed in a future version

kind/scale permissions are required to check current scale and to apply scale updates to targets

Development

export RESOURCE_AUTOSCALER_TESTING_MODE=yes ; inotifyrun go run ./main.go -- -v=9 --logging-format=json