Cyberithub

How to prevent automatic downscaling of your workload in Kubernetes Cluster

Advertisements

In this article, we will see how to prevent automatic downscaling of your deployment replica in a Kubernetes cluster. I am sure you must have been using kube-downscaler to scale down your workload during off business hours in order to save cost. But at the same time it is also possible that you might be having some critical application that cannot be scaled down during off business hours. For cases like this, you have to make sure to disable the automatic downscaling of your deployment replica as the application may need all replica running at all times. This can be easily achieved by setting an annotation to prevent automatic downscaling of your workload.

 

What is kube-downscaler?

The kube-downscaler is a Kubernetes cluster tool used to scale down workloads (Deployments, StatefulSets, etc.) during off business hours to save costs. It uses annotations on Kubernetes resources to define when they should be scaled down and back up. It runs as a deployment inside the cluster and continuously monitors workloads. It basically uses the local time of the cluster or a specified timezone to scale workloads based on business hours.

 

How to prevent automatic downscaling of your workload in Kubernetes Cluster

How to prevent automatic downscaling of your workload in Kubernetes Cluster

Also Read: How to Install and Use Velero to Backup Kubernetes Cluster

To prevent automatic downscaling, you have to basically set an annotation provided by kube-downscaler in your workload. This annotation is called downscaler/exclude that you have to set it as true as you can see in below code.

......
metadata:
  annotations:
    downscaler/exclude: true
......

If you set annotation like above then kube-downscaler will avoid removing replicas during off business hours. This will exclude all resources in namespace. Let's understand its usage by looking into one example deployment manifest file called cyberithub-app.yaml as shown below.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cyberithub-app
  annotations:
    downscaler/exclude: "true"
spec:
   replicas: 3
   selector:
      matchLabels:
         app: cyberithub-app
    template:
      metadata:
        labels:
          app: cyberithub-app
      spec:
        containers:
        - name: cyberithub-container
          image: nginx

The annotation downscaler/exclude: "true" used in above deployment file will prevent this deployment from being scaled down by the Kube Downscaler. To apply this configuration in your cluster, run kubectl apply -f cyberithub-app.yaml as shown below.

cyberithub@ubuntu:~$ kubectl apply -f cyberithub-app.yaml

To apply the annotation in existing deployment, you can use kubectl annotate deployment cyberithub-app.yaml downscaler/exclude="true" command as shown below.

cyberithub@ubuntu:~$ kubectl annotate deployment cyberithub-app.yaml downscaler/exclude="true"

You can apply this annotation to Deployments, StatefulSets, DaemonSets, and CronJobs.

Leave a Comment