Spotinst in-cluster Autoscaler

When choosing the pod (In-Cluster) option for k8s autoscaling, the Elastigroup will work with a designated pod inside your Kubernetes cluster that will report constant updates about the clusters’ condition via a one-way link.

Using that information, the Elastigroup will scale the cluster up or down according to the overall nodes utilization and your pods’ needs.

In order to create this connection between your k8s cluster and Elastigroup, you will need to implement a small configuration change on both the k8s cluster side and the Elastigroup side as instructed below;


Elastigroup Configuration

Please create an Elastigroup and configure the incluster k8s integration using a pod mode with a cluster-identifier (important!),  then configure the autoscaling parameters for the k8s.

API example

"kubernetes": {
     "integrationMode": "pod",
     "clusterIdentifier": "cluster-test"


Terraform Example

resource "spotinst_aws_group" "example" {

  kubernetes_integration {
    integration_mode   = "pod"
    cluster_identifier = "k8s-cluster-name"

    autoscale_is_enabled = true
    autoscale_cooldown   = 300
    autoscale_headroom {
      cpu_per_unit    = 2048
      memory_per_unit = 1024
      num_of_units    = 10
    autoscale_down {
      evaluation_periods = 5


What is Headroom?

A buffer of spare capacity (in terms of both memory and CPU) to make sure that when we want to scale more tasks, we don’t have to wait for new instances, and also to prevent instances from being over-utilized.

Each headroom unit consists of 2 definitions: one for CPU units “cpuPerUnit” (1024 units = 1 vCPU) and one for Memory “memoryPerUnit” (in MiB). Also, numOfUnits the number of units to reserve for the actual headroom in the cluster.


NOTE: Headroom takes precedence over scaling operations.



Kuberenetes Configuration

In order to run the Spotinst in-cluster autoscaler, you’ll need to run the following controller application in your k8s cluster spotinst-kubernetes-cluster-controller
This controller needs parameters

  1. spotinst.token – The Spotinst access token (can be generated from the Spotinst console / API)
  2. spotinst.account – The spotinst account Id (Learn more about Accounts and Organizations)
  3. spotinst.cluster-identifier – This identifier should be identical to the clusterIdentifier that was configured on the Elastigroup.


Installing the Controller

1. Create a yaml file configMap.yaml with the following parameters;

kind: ConfigMap
apiVersion: v1
 name: spotinst-kubernetes-cluster-controller-config
 namespace: kube-system 
 spotinst.token: <TOKEN>
 spotinst.account: <ACCOUNT_ID>
 spotinst.cluster-identifier: <IDENTIFIER>

(please replace <TOKEN> <ACCOUNT_ID> and <IDENTIFIER> )


2. Load the parameters into the cluster config

kubectl apply -f configMap.yaml


3. Install the controller and its dependencies

kubectl apply -f http://spotinst-public.s3.amazonaws.com/integrations/kubernetes/cluster-controller/spotinst-kubernetes-cluster-controller.yaml


Now the spotinst-kubernetes-cluster-controller is installed and should be reporting its heartbeat to the relevant Spotinst Elastigroup.