Table of Contents
In this article, we will see how to install kube-downscaler in Kubernetes cluster using Kubectl. If you are running your applications in a kubernetes cluster and wanted to save some cost of running workloads during less traffic hours or during off business hours when the load is very minimal then kube-downscaler is a must to use tool for this specific use cases. It can easily scale down the workloads (Deployments, StatefulSets, CronJobs, etc.) outside of business hours to save costs and can even scale back during normal business hours.
It is also very easy to use in your applications. You just have to deploy it in your cluster as a normal deployment and then start using its different annotations in your applications as per your requirement. While in our earlier article we have already seen a method to install it using kustomize and kubectl, here we will see even much simpler way to install by using just kubectl utility. So, let's begin. If you haven't seen the earlier article then check How to Install kube-downscaler in Kubernetes cluster using Kustomize and Kubectl
How to install kube-downscaler in Kubernetes cluster using Kubectl
Also Read: How to trigger a cronjob manually in Kubernetes Cluster
Step 1: Prerequisites
a) You should have a running Kubernetes Cluster.
b) You should have kubectl
and git
installed and available to use.
c) You should have sudo
or root
access to run kubectl
commands.
d) You should have access to kubernetes control node to run all the required commands.
Step 2: Clone git repo
You have to first clone the latest repo from official page by using git clone https://codeberg.org/hjacobs/kube-downscaler.git
command as shown below. This will create a directory kube-downscaler in current working path and copy all contents in it.
cyberithub@cluster:~$ git clone https://codeberg.org/hjacobs/kube-downscaler.git Cloning into 'kube-downscaler'... remote: Enumerating objects: 1203, done. remote: Counting objects: 100% (461/461), done. remote: Compressing objects: 100% (131/131), done. remote: Total 1203 (delta 429), reused 330 (delta 330), pack-reused 742 (from 1) Receiving objects: 100% (1203/1203), 392.08 KiB | 427.00 KiB/s, done. Resolving deltas: 100% (809/809), done.
Step 3: Remove kustomization.yaml file
Since the repo contents has kustomization.yaml file as well to support the working of kustomize tool, for kubectl it is not required. So we will just remove this file in order to install through just kubectl utility. To remove, you can simply use rm -rf kube-downscaler/deploy/kustomization.yaml
command as shown below.
cyberithub@cluster:~$ rm -rf kube-downscaler/deploy/kustomization.yaml
Step 4: Install kube-downscaler
Now you can deploy all the required kubernetes objects from deploy directory in default namespace. To create or update existing objects, run kubectl apply -f kube-downscaler/deploy/
command as shown below. As you can see, all objects are successfully created.
cyberithub@cluster:~$ kubectl apply -f kube-downscaler/deploy/ configmap/kube-downscaler created deployment.apps/kube-downscaler created serviceaccount/kube-downscaler created clusterrole.rbac.authorization.k8s.io/kube-downscaler created clusterrolebinding.rbac.authorization.k8s.io/kube-downscaler created
Step 5: Verify Installation
After successful deployment, you can verify the installation status by running kubectl get all -n default
command as shown below. This will list out all the kubernetes objects created under default namespace.
cyberithub@cluster:~$ kubectl get all -n default NAME READY STATUS RESTARTS AGE pod/kube-downscaler-bc8888bf4-phr8j 1/1 Running 0 6s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d18h NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/kube-downscaler 1/1 1 1 6s NAME DESIRED CURRENT READY AGE replicaset.apps/kube-downscaler-bc8888bf4 1 1 1 6s
Step 6: Scales down workload
To verify the usage of kube-downscaler, let's see a demo where we will scales down the replica of an application called cyberithub-app
to 1
from original deployment replica of 2
on Saturday
and Sunday
from 1:00 AM to midnight (New York time)
. Outside of these hours, application deployment will run at full capacity of 2
replicas as shown below.
apiVersion: apps/v1 kind: Deployment metadata: name: cyberithub-app annotations: downscaler/downtime: "Sat-Sun 01:00-23:59 America/New_York" downscaler/downtime-replicas: "1" spec: replicas: 2 selector: matchLabels: app: cyberithub-app template: metadata: labels: app: cyberithub-app spec: containers: - name: cyberithub-container image: nginx:latest
Step 7: Delete all objects
Once you are done using kube-downscaler, you can also choose to remove entire deployed objects by using kubectl delete -f kube-downscaler/deploy/
command as shown below.
cyberithub@cluster:~$ kubectl delete -f kube-downscaler/deploy/ configmap "kube-downscaler" deleted deployment.apps "kube-downscaler" deleted serviceaccount "kube-downscaler" deleted clusterrole.rbac.authorization.k8s.io "kube-downscaler" deleted clusterrolebinding.rbac.authorization.k8s.io "kube-downscaler" deleted