In today's article, I will show you how to deploy Cluster AutoScalar on AWS EKS cluster. Cluster Autoscaler is a tool that automatically adjusts the size of a Kubernetes cluster in response to workload demand. It works by periodically evaluating the resource utilization of the pods running on the cluster and comparing it to the target utilization set by the user. If the actual utilization exceeds the target, Cluster Autoscaler will spin up additional nodes in the cluster to accommodate the additional workload. Conversely, if the actual utilization falls below the target, Cluster Autoscaler will remove unnecessary nodes to save resources. By automatically scaling the cluster in response to workload demand, Cluster Autoscaler helps ensure that pods have the resources they need to function properly, while also minimizing resource waste.
Create a EKS Cluster
Before we start, we need to create a EKS cluster. If you already have a EKS cluster, you can skip this step. In this step we will create a simple EKS cluster using eksctl byusing the below config file.
metadata: name:demo## your cluster name region:ap-southeast-1## your region
iam: withOIDC:true## enable OIDC serviceAccounts: -metadata: name:cluster-autoscaler## service account name (you can use any name) namespace:kube-system## namespace which you want to create the service account wellKnownPolicies: autoScaler:true## enable cluster autoscaler policy roleName:cluster-autoscaler## role name (you can use any name) roleOnly:true## create only role
managedNodeGroups: -name:demo-nodegroup instanceType:t3.large desiredCapacity:1 minSize:1 maxSize:10 privateNetworking:true## enable private networking tags: k8s.io/cluster-autoscaler/enabled:"true"## enable cluster autoscaler k8s.io/cluster-autoscaler/<your-cluster-name>:"owned"## make sure to replace <your-cluster-name> with your cluster name
To create the cluster, run the below command.
1
eksctl create cluster -f cluster-oidc.yaml
Warning:
The Cluster Autoscaler requires the following tags on your Auto-Scaling groups so that they can be auto-discovered ( EC2 -> Auto-Scaling groups -> `node-group-name` -> Tags )
Now we have deployed cluster autoscaler. Let’s check the status of cluster autoscaler.
1
kubectl get pods -n kube-system
Above command will give you the output as below.
1 2
NAME READY STATUS RESTARTS AGE cluster-autoscaler-5f4f7f7f4f-5j4xg 1/1 Running 0 2m
Deploy Sample Application
Now we have deployed cluster autoscaler. Let’s deploy a sample application to test the cluster autoscaler. We will deploy a sample application using below command.
In the output of the above command, it shows that, the pod was triggered by the cluster autoscaler. And also you can see the node count of the cluster is increased.
Conclusion
In this tutorial, we have learned how to deploy Cluster AutoScalar on AWS EKS cluster. You can obtain all the required script from this GitHub repository. If you have any issue regarding this tutorial, mention your issue in the comment section or reach me through my E-mail.