headroom-controller

by Helm

Helm chartv0.1.8App 0.1.0

A Helm chart for headroom-controller - Kubernetes resource reservation controller

About this chart

Headroom Controller Helm Chart

Speed up scaling up and rolling out of workloads by pre-provisioning headroom in your Kubernetes cluster.

This component is licensed for OpenFaaS Standard or Enterprise customers.

Prerequisites

You do not need to use OpenFaaS to install this chart and use the headroom-controller. It is a standalone component.

  • Kubernetes

  • Helm

  • Some form of autoscaling node group, or Cluster Autoscaler, or Karpenter, etc.

  • An OpenFaaS license

    Obtain a license or trial at https://openfaas.com/pricing

If you're not an OpenFaaS Standard or OpenFaaS for Enterprises customer, you can purchase a license here. Click the "Headroom Controller" option.

A license is required for each cluster/installation.

You can build a direct checkout link as follows, changing ?quantity=N for instance:

# 2x clusters:
https://subscribe.openfaas.com/checkout/buy/6f00c083-378f-41dd-ab01-aaf2ebfac73f?quantity=2


# 3x clusters:
https://subscribe.openfaas.com/checkout/buy/6f00c083-378f-41dd-ab01-aaf2ebfac73f?quantity=2

Demo

Watch a live demo with the Cluster Autoscaler and K3s:

Installation

Add the repository

helm repo add openfaas https://openfaas.github.io/faas-netes/ && \
  helm repo update

Install from the chart repository

Create the required secret with your license:

kubectl create ns default

kubectl create secret generic \
  -n default \
  openfaas-license \
  --from-file license=$HOME/.openfaas/LICENSE

OpenFaaS customers - use your existing license key for the specific environment. If you're not an OpenFaaS customer, use the key you received from LemonSqueezy via email.

Install with defaults:

helm upgrade --install headroom-controller \
  openfaas/headroom-controller \
  --namespace default

Or create a file named values-custom.yaml if you wish to customise the installation.

rbac:
  role: Role

Then install with custom values:

helm upgrade --install headroom-controller \
  openfaas/headroom-controller \
  --namespace default \
  --values values-custom.yaml

The chart can also be installed into a custom namespace i.e. openfaas or kube-system by altering the --namespace flag.

If you install into a different namespace, create the openfaas-license secret in that namespace first.

Install from local chart

If you are working on a patch for the helm chart, you can deploy it directly from a local folder.

# Clone the repository
git clone https://github.com/openfaas/faas-netes.git --depth=1
cd faas-netes

# Install the chart
helm upgrade --install headroom-controller \
  ./chart/headroom-controller \
  --namespace default

Usage

  1. Create a default priority priorityClassName
kubectl apply -f - << EOF
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: default
value: 1000
globalDefault: true
description: "Default priority class for all pods"
EOF
  1. Create a low priority class for the headroom Custom Resources
kubectl apply -f - <<EOF
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: headroom
description: Low priority class for headroom pods
globalDefault: false
preemptionPolicy: Never
value: -10
EOF
  1. Create a headroom resource:
kubectl apply -f - <<EOF
apiVersion: openfaas.com/v1
kind: Headroom
metadata:
  name: example
spec:
  replicas: 1
  requests:
    cpu: "100m"
    memory: "128Mi"
  priorityClassName: "headroom"
EOF
  1. Check the status:

    kubectl get headrooms

  2. Scale the headroom:

    kubectl scale headroom example --replicas=2

Advanced example - scale a headroom down from a Cron Job

Imagine you wanted to scale down the headroom resource overnight.

Here's an example of how Kubernetes-native resources can be used.

kind: CronJob
apiVersion: batch/v1
metadata:
  name: scale-headroom
  namespace: default
spec:
  schedule: "0 0 * * * *"
  successfulJobsHistoryLimit: 5 # Keep 5 successful jobs
  failedJobsHistoryLimit: 1 # Keep 1 failed job
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: headroom-scaler
          restartPolicy: OnFailure
          containers:
            - name: kubectl
              image: alpine/k8s:1.33.3 # Or a specific version
              command:
                - "/bin/sh"
                - "-c"
                - |
                  apk add --no-cache kubectl
                  kubectl scale headroom/example --replicas=0
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: headroom-scaler
  namespace: default # Or your target namespace

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding # Or RoleBinding if headroom controller is namespace scoped
metadata:
  name: headroom-scaler-rb
  namespace: default
subjects:
  - kind: ServiceAccount
    name: headroom-scaler
    namespace: default
roleRef:
  kind: ClusterRole # Or Role if headroom controller is namespace scoped
  name: headroom-scaler-role
  apiGroup: rbac.authorization.k8s.io

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole # Or Role if headroom controller is namespace scoped
metadata:
  name: headroom-scaler-role
  namespace: default
rules:
  - apiGroups: ["openfaas.com"]
    resources: ["headrooms", "headrooms/scale"]
    verbs: ["get", "patch", "update"]

Configuration

Specify each parameter using the --set key=value[,key=value] argument to helm install.

See values.yaml for detailed configuration.

ParameterDescriptionDefault
imageContainer imageSee values.yaml
replicasNumber of controller replicas. It is not recommended to alter this value.1
imagePullPolicyImage pull policyIfNotPresent
imagePullSecretsImage pull secrets[]
nameOverrideOverride chart name""
fullnameOverrideOverride full chart name""
rbac.createCreate RBAC resourcestrue
rbac.roleRole type (Role or ClusterRole)ClusterRole
serviceAccount.createCreate service accounttrue
serviceAccount.annotationsService account annotations{}
serviceAccount.nameService account name""
podAnnotationsPod annotations{}
podSecurityContextPod security context{}
securityContextContainer security context{}
resources.limits.cpuCPU limit250m
resources.limits.memoryMemory limit256Mi
resources.requests.cpuCPU request50m
resources.requests.memoryMemory request64Mi
nodeSelectorNode selector for pod assignment{}
tolerationsTolerations for pod assignment[]
affinityAffinity rules for pod assignment{}
metrics.enabledEnable metrics collectionfalse
leaderElection.enabledEnable leader electiontrue
leaderElection.namespaceNamespace for leader election"default"
logging.levelLog levelinfo

Uninstalling

helm uninstall headroom-controller

Note: This will not remove the CRDs. To remove them:

kubectl delete crd headrooms.openfaas.com

Deploy headroom-controller with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has headroom-controller 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 chartheadroom-controller is pinned at v0.1.8 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