cluster-autoscaler

by joaquinito2051

Helm chartv0.13.2App 1.13.1

Scales worker nodes within autoscaling groups.

About this chart

cluster-autoscaler

The cluster autoscaler scales worker nodes within an AWS autoscaling group (ASG) or Spotinst Elastigroup.

TL;DR:

$ helm install <helm-repo>/cluster-autoscaler --name my-release --set "autoscalingGroups[0].name=your-asg-name,autoscalingGroups[0].maxSize=10,autoscalingGroups[0].minSize=1"

$ helm install stable/cluster-autoscaler --name my-release --set "autoscalingGroups[0].name=your-asg-name,autoscalingGroups[0].maxSize=10,autoscalingGroups[0].minSize=1"

Introduction

This chart bootstraps a cluster-autoscaler deployment on a Kubernetes cluster using the Helm package manager.

Prerequisites

  • Kubernetes 1.8+

older versions may work by overriding the image. Cluster-autoscaler internally simulates the scheduler and bugs between mismatched versions may be subtle.

  • Azure AKS specific Prerequisites:
    • Kubernetes 1.10+ with RBAC-enabled

Installing the Chart

By default, no deployment is created and nothing will autoscale.

You must provide some minimal configuration, either to specify instance groups or enable auto-discovery. It is not recommended to do both.

Either:

  • set autoDiscovery.clusterName and tag your autoscaling groups appropriately (--cloud-provider=aws only) or
  • set at least one ASG as an element in the autoscalingGroups array with its three values: name, minSize and maxSize.

To install the chart with the release name my-release:

Using auto-discovery of tagged instance groups

AWS

Auto-discovery finds ASGs tags as below and automatically manages them based on the min and max size specified in the ASG. cloudProvider=aws only.

  1. tag the ASGs with key k8s.io/cluster-autoscaler/enabled and key kubernetes.io/cluster/<YOUR CLUSTER NAME>
  2. verify the IAM Permissions
  3. set autoDiscovery.clusterName=<YOUR CLUSTER NAME>
  4. set awsRegion=<YOUR AWS REGION>
  5. set awsAccessKeyID=<YOUR AWS KEY ID> and awsSecretAccessKey=<YOUR AWS SECRET KEY> if you want to use AWS credentials directly instead of an instance role
$ helm install <helm-repo>/cluster-autoscaler --name my-release --set autoDiscovery.clusterName=<CLUSTER NAME>

$ helm install stable/cluster-autoscaler --name my-release --set autoDiscovery.clusterName= The auto-discovery section provides more details and examples

GCE

Required parameters

  • autoDiscovery.clusterName=any-name
  • --cloud-provider=gce
  • autoscalingGroupsnamePrefix[0].name=your-ig-prefix,autoscalingGroupsnamePrefix[0].maxSize=10,autoscalingGroupsnamePrefix[0].minSize=1

To use Managed Instance Group (MIG) auto-discovery, provide a YAML file setting autoscalingGroupsnamePrefix (see values.yaml) or use --set when installing the Chart - e.g.

$ helm install <helm-repo>/cluster-autoscaler \
--name my-release \
--set autoDiscovery.clusterName=<CLUSTER NAME> \
$ helm install stable/cluster-autoscaler \
--set cloudProvider=gce \
--set "autoscalingGroupsnamePrefix[0].name=your-ig-prefix,autoscalingGroupsnamePrefix[0].maxSize=10,autoscalingGroupsnamePrefix[0].minSize=1"

Note that your-ig-prefix should be a prefix matching one or more MIGs, and not the full name of the MIG. For example, to match multiple instance groups - k8s-node-group-a-standard, k8s-node-group-b-gpu, you would use a prefix of k8s-node-group-.

In the event you want to explicitly specify MIGs instead of using auto-discovery, set members of the autoscalingGroups array directly - e.g.

# where 'n' is the index, starting at 0
-- set autoscalingGroups[n].name=https://content.googleapis.com/compute/v1/projects/$PROJECTID/zones/$ZONENAME/instanceGroupManagers/$FULL-MIG-NAME,autoscalingGroups[n].maxSize=$MAXSIZE,autoscalingGroups[n].minSize=$MINSIZE

Azure AKS

Required Parameters

  • cloudProvider=azure
  • autoscalingGroups[0].name=your-agent-pool,autoscalingGroups[0].maxSize=10,autoscalingGroups[0].minSize=1
  • azureClientID: "your-service-principal-app-id"
  • azureClientSecret: "your-service-principal-client-secret"
  • azureSubscriptionID: "your-azure-subscription-id"
  • azureTenantID: "your-azure-tenant-id"
  • azureClusterName: "your-aks-cluster-name"
  • azureResourceGroup: "your-aks-cluster-resource-group-name"
  • azureVMType: "AKS"
  • azureNodeResourceGroup: "your-aks-cluster-node-resource-group"

Specifying groups manually (only aws)

Without autodiscovery, specify an array of elements each containing ASG name, min size, max size. The sizes specified here will be applied to the ASG, assuming IAM permissions are correctly configured.

  1. verify the IAM Permissions
  2. Either provide a yaml file setting autoscalingGroups (see values.yaml) or use --set e.g.:
$ helm install <helm-repo>/cluster-autoscaler --name my-release --set "autoscalingGroups[0].name=your-asg-name,autoscalingGroups[0].maxSize=10,autoscalingGroups[0].minSize=1"

$ helm install stable/cluster-autoscaler --name my-release --set "autoscalingGroups[0].name=your-asg-name,autoscalingGroups[0].maxSize=10,autoscalingGroups[0].minSize=1"

Uninstalling the Chart

To uninstall my-release:

$ helm delete my-release

The command removes all the Kubernetes components associated with the chart and deletes the release.

Tip: List all releases using helm list or start clean with helm delete --purge my-release

Configuration

The following table lists the configurable parameters of the cluster-autoscaler chart and their default values.

ParameterDescriptionDefault
affinitynode/pod affinitiesNone
autoDiscovery.clusterNameenable autodiscovery for name in ASG tag (only cloudProvider=aws). Must be set for cloudProvider=gce, but no MIG tagging required."" required unless autoscalingGroups[] provided
autoscalingGroups[].nameautoscaling group nameNone. Required unless autoDiscovery.enabled=true
autoscalingGroups[].maxSizemaximum autoscaling group sizeNone. Required unless autoDiscovery.enabled=true
autoscalingGroups[].minSizeminimum autoscaling group sizeNone. Required unless autoDiscovery.enabled=true
awsRegionAWS region (required if cloudProvider=aws)us-east-1
awsAccessKeyIDAWS access key ID (if AWS user keys used)""
awsSecretAccessKeyAWS access secret key (if AWS user keys used)""
autoscalingGroupsnamePrefix[].nameGCE MIG name prefix (the full name is invalid)None. Required for cloudProvider=gce
autoscalingGroupsnamePrefix[].maxSizemaximum MIG sizeNone. Required for cloudProvider=gce
autoscalingGroupsnamePrefix[].minSizeminimum MIG sizeNone. Required for cloudProvider=gce
sslCertPathPath on the pod where ssl ca cert exists/etc/ssl/certs/ca-certificates.crt
sslCertHostPathPath on the host where ssl ca cert exists/etc/ssl/certs/ca-certificates.crt
cloudProvideraws or spotinst are currently supported for AWS. gce for GCE. azure for Azure AKSaws
image.repositoryImagek8s.gcr.io/cluster-autoscaler
image.tagImage tagv1.13.1
image.pullPolicyImage pull policyIfNotPresent
extraArgsadditional container arguments{}
podDisruptionBudgetPod disruption budgetmaxUnavailable: 1
extraEnvadditional container environment variables{}
nodeSelectornode labels for pod assignment{}
podAnnotationsannotations to add to each pod{}
deployment.apiVersionapiVersion for the deploymentextensions/v1beta1
rbac.createIf true, create & use RBAC resourcesfalse
rbac.serviceAccountNameexisting ServiceAccount to use (ignored if rbac.create=true)default
rbac.pspEnabledMust be used with rbac.create true. If true, creates & uses RBAC resources required in the cluster with Pod Security Policies enabled.false
replicaCountdesired number of pods1
priorityClassNamepriorityClassNamenil
dnsPolicydnsPolicynil
resourcespod resource requests & limits{}
service.annotationsannotations to add to servicenone
service.clusterIPIP address to assign to service""
service.externalIPsservice external IP addresses[]
service.loadBalancerIPIP address to assign to load balancer (if supported)""
service.loadBalancerSourceRangeslist of IP CIDRs allowed access to load balancer (if supported)[]
service.servicePortservice port to expose8085
service.portNamename for service porthttp
service.typetype of service to createClusterIP
spotinst.accountSpotinst Account ID (required if cloudprovider=spotinst)""
spotinst.tokenSpotinst API token (required if cloudprovider=spotinst)""
spotinst.image.repositoryImage (used if cloudProvider=spotinst)spotinst/kubernetes-cluster-autoscaler
spotinst.image.tagImage tag (used if cloudProvider=spotinst)v0.6.0
spotinst.image.pullPolicyImage pull policy (used if cloudProvider=spotinst)IfNotPresent
tolerationsList of node taints to tolerate (requires Kubernetes >= 1.6)[]
serviceMonitor.enabledif true, creates a Prometheus Operator ServiceMonitorfalse
serviceMonitor.intervalInterval that Prometheus scrapes Cluster Autoscaler metrics10s
serviceMonitor.namespaceNamespace which Prometheus is running inmonitoring
serviceMonitor.selectorDefault to kube-prometheus install (CoreOS recommended), but should be set according to Prometheus install{ prometheus: kube-prometheus }
azureClientIDService Principal ClientID with contributor permission to Cluster and Node ResourceGroupnone
azureClientSecretService Principal ClientSecret with contributor permission to Cluster and Node ResourceGroupnone
azureSubscriptionIDAzure subscription where the resources are locatednone
azureTenantIDAzure tenant where the resources are locatednone
azureClusterNameAzure AKS cluster namenone
azureResourceGroupAzure resource group that the cluster is locatednone
azureVMType: "AKS"Azure VM typeAKS
azureNodeResourceGroupazure resource group where the clusters Nodes are located, typically set as MC_<cluster-resource-group-name>_<cluster-name>_<location>none
azureUseManagedIdentityExtensionWhether to use Azure's managed identity extension for credentialsfalse

Specify each parameter you'd like to override using a YAML file as described above in the installation section or by using the --set key=value[,key=value] argument to helm install. For example, to change the region and expander:

Specify each parameter you'd like to override using a YAML file as described above in the [installation](#installing-the-chart) section or by using the `--set key=value[,key=value]` argument to `helm install`. For example, to change the region and [expander](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#what-are-expanders):
$ helm install <helm-repo>/cluster-autoscaler --name my-release \
    --set extraArgs.expander=most-pods \
    --set awsRegion=us-west-1
$ helm install stable/cluster-autoscaler --name my-release \

IAM

The worker running the cluster autoscaler will need access to certain resources and actions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "autoscaling:DescribeAutoScalingGroups",
                "autoscaling:DescribeAutoScalingInstances",
                "autoscaling:DescribeLaunchConfigurations",
                "autoscaling:DescribeTags",
                "autoscaling:SetDesiredCapacity",
                "autoscaling:TerminateInstanceInAutoScalingGroup"
            ],
            "Resource": "*"
        }
    ]
}
  • DescribeTags is required for autodiscovery.
  • DescribeLaunchconfigurations is required to scale up an ASG from 0

Unfortunately AWS does not support ARNs for autoscaling groups yet so you must use "*" as the resource. More information here.

Auto-discovery

For auto-discovery of instances to work, they must be tagged with k8s.io/cluster-autoscaler/enabled and kubernetes.io/cluster/<ClusterName>

The value of the tag does not matter, only the key.

An example kops spec excerpt:

apiVersion: kops/v1alpha2
kind: Cluster
metadata:
  name: my.cluster.internal
spec:
  additionalPolicies:
    node: |
      [
        {"Effect":"Allow","Action":["autoscaling:DescribeAutoScalingGroups","autoscaling:DescribeAutoScalingInstances","autoscaling:DescribeLaunchConfigurations","autoscaling:DescribeTags","autoscaling:SetDesiredCapacity","autoscaling:TerminateInstanceInAutoScalingGroup"],"Resource":"*"}
      ]
      ...
---
apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
  labels:
    kops.k8s.io/cluster: my.cluster.internal
  name: my-instances
spec:
  cloudLabels:
    k8s.io/cluster-autoscaler/enabled: ""
    kubernetes.io/cluste

Deploy cluster-autoscaler with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has cluster-autoscaler on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartcluster-autoscaler is pinned at v0.13.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply