> For the complete documentation index, see [llms.txt](https://doc.cloudbit.ch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.cloudbit.ch/products/kubernetes/resources/cluster-autoscaler.md).

# Cluster Autoscaler

## Introduction

Cluster Autoscaler is a component that automatically adjusts the size of a Kubernetes Cluster so that all pods have a place to run and there are no unneeded nodes.

The cluster autoscaler for CloudBit scales worker nodes within any specified CloudBit Kubernetes cluster.

## Installation

As there is no concept of a node group within CloudBit Cloud's Kubernetes offering, the configuration required is quite simple. You need to set:

* Your CloudBit Application Token
* The Kubernetes Cluster's ID (not the name)
* The minimum and maximum number of **worker** nodes you want (the master is excluded)

1. Please adjust the following bold values in the yaml file below:

* Minimum & Maximum of worker nodes (for example minimum 3 and maximal nine): `nodes=3:9:workers`<br>
* Generate an application token in <https://my.cloudbit.ch/#/organization/applications> and convert it to a base64 string and replace the \*\*api-token\*\* value.<br>
* Retrieve the cluster ID from your Kubernetes Cluster, convert it to a base64 string and replace the \*\*cluster-id\*\* value.

```
cluster-autoscaler.yaml
 
---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-addon: cluster-autoscaler.addons.k8s.io
    k8s-app: cluster-autoscaler
  name: cluster-autoscaler
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cluster-autoscaler
  labels:
    k8s-addon: cluster-autoscaler.addons.k8s.io
    k8s-app: cluster-autoscaler
rules:
  - apiGroups: [""]
    resources:
      [
        "pods",
        "services",
        "replicationcontrollers",
        "persistentvolumeclaims",
        "persistentvolumes",
        "nodes",
        "endpoints",
        "namespaces",
        "configmaps",
      ]
    verbs: ["watch", "list", "get", "update", "create", "delete"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["watch", "list", "get", "create", "update", "delete", "patch"]
  - apiGroups: ["extensions"]
    resources: ["replicasets", "daemonsets"]
    verbs: ["watch", "list", "get"]
  - apiGroups: ["policy"]
    resources: ["poddisruptionbudgets"]
    verbs: ["watch", "list"]
  - apiGroups: ["apps"]
    resources: ["statefulsets", "replicasets", "daemonsets"]
    verbs: ["watch", "list", "get"]
  - apiGroups: ["storage.k8s.io"]
    resources:
      ["storageclasses", "csinodes", "csistoragecapacities", "csidrivers"]
    verbs: ["watch", "list", "get"]
  - apiGroups: ["batch", "extensions"]
    resources: ["jobs"]
    verbs: ["get", "list", "watch", "patch"]
  - apiGroups: ["coordination.k8s.io"]
    resources: ["leases"]
    verbs: ["get", "create", "update"]
  - apiGroups: [""]
    resources: ["pods/eviction"]
    verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cluster-autoscaler
  labels:
    k8s-addon: cluster-autoscaler.addons.k8s.io
    k8s-app: cluster-autoscaler
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-autoscaler
subjects:
  - kind: ServiceAccount
    name: cluster-autoscaler
    namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: cluster-autoscaler
  namespace: kube-system
  labels:
    k8s-addon: cluster-autoscaler.addons.k8s.io
    k8s-app: cluster-autoscaler
rules:
  - apiGroups: ["coordination.k8s.io"]
    resources: ["leases"]
    verbs: ["create", "get", "update"]
    resourceNames: ["cluster-autoscaler"]
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["create", "list", "watch", "update"]
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cluster-autoscaler
  namespace: kube-system
  labels:
    app: cluster-autoscaler
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cluster-autoscaler
  template:
    metadata:
      labels:
        app: cluster-autoscaler
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8085"
    spec:
      serviceAccountName: cluster-autoscaler
      containers:
        - image: flowswiss/cluster-autoscaler:cloudbit 
          name: cluster-autoscaler
          imagePullPolicy: Always
          resources:
            limits:
              cpu: 100m
              memory: 300Mi
            requests:
              cpu: 100m
              memory: 300Mi
          command:
            - ./cluster-autoscaler
            - --v=4
            - --stderrthreshold=info
            - --cloud-provider=cloudbit
            - --nodes=1:6:workers
            - --skip-nodes-with-local-storage=false
            - --skip-nodes-with-system-pods=false
          env:
            - name: CLOUDBIT_API_TOKEN
              valueFrom:
                secretKeyRef:
                  key: **api-token** #base64_encoded_api_token
                  name: cluster-autoscaler-secrets
            - name: CLOUDBIT_CLUSTER_ID
              valueFrom:
                secretKeyRef:
                  name: cluster-autoscaler-secrets
                  key: **cluster-id** #base64_encoded_cluster_id
            - name: CLOUDBIT_API_URL
              valueFrom:
                secretKeyRef:
                  name: cluster-autoscaler-secrets
                  key: aHR0cHM6Ly9hcGkuY2xvdWRiaXQuY2gv #base64_encoded_api_url
```

2. Apply the yaml file with kubectl in your desired Kubernetes Cluster.<br>
3. Follow the official documentation to configure the behavior of the cluster autoscaler: <https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler>\ <br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doc.cloudbit.ch/products/kubernetes/resources/cluster-autoscaler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
