/downscaler

Poor man's cost savings for an eks cluster.

Primary LanguageGoBSD 2-Clause "Simplified" LicenseBSD-2-Clause

k8s cluster downscaler

This project is a poor man's attempt to reduce cost with running clusters. The idea behind it is to automatically scale up/down the number of worker nodes. It is assumed that the clusters are used within certain time frames, thus not being needed outside them, e.g. evenings,weekends...etc

What is it?

The downscaler is a lambda function triggered at specific times. There are two available schedules to be set, one for upscaling and another for downscaling.

Build the downscaler

Run the following in the repository's root directory:

$ make

This will build the lambda source code under src/ and create a source.zip file.

Deploy the downscaler

The terraform code associated with the entire infra is found in the terraform directory.

Make sure you have the correct AWS credentials in place, fill in the variables as needed and proceed to apply.

Requirements

Name Version
terraform ~> 1.1.5
aws 4.18.0

Providers

Name Version
aws 4.18.0

Resources

Name Type
aws_cloudwatch_event_rule.asg_down_scale_rule resource
aws_cloudwatch_event_rule.asg_up_scale_rule resource
aws_cloudwatch_event_target.asg_down_scale_target resource
aws_cloudwatch_event_target.asg_up_scale_target resource
aws_iam_policy.autoscaling_lifecycle_policy resource
aws_iam_role.ec2_autoscaling_event_role resource
aws_iam_role_policy_attachment.autoscaling_lifecycle_policy_attachment resource
aws_iam_role_policy_attachment.cloud_watch_policy_attachment resource
aws_lambda_function.asg_scale_function resource
aws_lambda_permission.downscale_allow_cloudwatch resource
aws_lambda_permission.upscale_allow_cloudwatch resource
aws_autoscaling_groups.current_groups data source
aws_iam_policy_document.instance_assume_role_policy data source

Inputs

Name Description Type Default Required
cluster_name Name of the cluster used for detecting the attached autoscaling-groups. string n/a yes
lambda_file Path to the zip file containing the lambda function. (see scaler.zip) string n/a yes
scale_down_max_size Max capacity after a scale down. number 1 no
scale_down_schedule Set the down scaling schedule. (expressed in UTC) string "cron(0 15 ? * MON-FRI *)" no
scale_in_protection Enable scale-in protection for new nodes after scale up. bool false no
scale_up_max_size Max capacity after a scale up. number 10 no
scale_up_schedule Set the up scaling schedule. (expressed in UTC) string "cron(0 6 ? * MON-FRI *)" no