Enable Cluster Autoscaler in EKS with easy steps

Enable Cluster Autoscaler in EKS with easy steps

Seven steps process to enable cluster autoscaler in EKS

Kubernetes offers human intervention free function to scale up or down the resources to meet the changing demands. Cloud Autoscaler is an EKS supported feature to enable on any existing cluster.

Prerequisites

  1. An existing Amazon EKS cluster
  2. Access to Kubeconfig file
  3. Kubectl and AWS Cli

Right now the applied IAM roles in your cluster and nodes would be looking like this. We will be adding new IAM policy in our IAM role on the nodes. Screenshot from 2022-01-24 01-22-26.png

Configuring Cluster Autoscaler

  1. Create a policy with following content. You can name it as ClusterAutoscalerPolicy.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "autoscaling:DescribeAutoScalingGroups",
                "autoscaling:DescribeAutoScalingInstances",
                "autoscaling:DescribeLaunchConfigurations",
                "autoscaling:DescribeTags",
                "autoscaling:SetDesiredCapacity",
                "autoscaling:TerminateInstanceInAutoScalingGroup",
                "ec2:DescribeLaunchTemplateVersions"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
  1. Attach this policy to the IAM Worker Node Role which is already in use.

eks (1).jpg

  1. Deploy the Cluster Autoscaler with the following command.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
  1. Add an annotation to the deployment with the following command.

    kubectl -n kube-system annotate deployment.apps/cluster-autoscaler cluster-autoscaler.kubernetes.io/safe-to-evict="false"
    
  2. Edit the Cluster Autoscaler deployment with the following command.

    kubectl -n kube-system edit deployment.apps/cluster-autoscaler
    

    This command will open the yaml file for your editting. Replace value with your own cluster name, and add the following command option --skip-nodes-with-system-pods=false to the command section under containers under spec. Save and exit the file by pressing :wq. The changes will be applied.

  3. Find an appropriate version of your cluster autoscaler in the link. The version number should start with version number of the cluster Kubernetes version. For example, if you have selected the Kubernetes version 1.17, you should find something like 1.17.x.

  4. Then, in the following command, set the Cluster Autoscaler image tag as that version you have found in the previous step.

    kubectl -n kube-system set image deployment.apps/cluster-autoscaler cluster-autoscaler=us.gcr.io/k8s-artifacts-prod/autoscaling/cluster-autoscaler:<YOUR-VERSION-HERE>
    

Conclusion

The Kubernetes Cluster Autoscaler is an easy to use function to prevent downtime when pods fail or are rescheduled onto other nodes by adjusting the number of nodes. This is typically already installed as a Deployment in an EKS cluster. Basic familiarity can save extensive human resources.