Skip to content

sparkfabrik/terraform-kubernetes-application-sleep-cycles

Repository files navigation

Terraform Kubernetes Application Sleep Cycles

This is a Terraform module to install a cron job on a Kubernetes cluster that uses the labels of application instances to perform a scale down to zero during predefined periods, thus reducing resource consumption, and then automatically restores the applications by scaling up at the end of the idle period.

Providers

Name Version
kubernetes >= 2.26

Requirements

Name Version
terraform >= 1
kubernetes >= 2.26

Inputs

Name Description Type Default Required
additional_protected_namespaces List of additional namespaces where the controller should not manage the scale of deployments. list(string) [] no
cluster_role_binding_name Name of the cluster role binding. string "custom:application-sleep-cycles:controller" no
cluster_role_name_prefix Name of the cluster role. string "custom:application-sleep-cycles:controller" no
configmap_name_prefix Name prefix for the Config Maps. string "application-sleep-cycles-config" no
create_namespace Create namespace. If false, the namespace must be created before using this module. bool true no
cronjob_timezone Timezone to use for the cron jobs. string "Europe/Rome" no
deployments_label_selector Label selector for the Deployments to be scaled during working-hours. map(string)
{
"sparkfabrik.com/application-availability": "working-hours"
}
no
k8s_additional_labels Set of additional labels to apply to all resources. map(string) {} no
k8s_labels Set of labels to apply to all resources. map(string)
{
"managed-by": "terraform",
"scope": "finops"
}
no
managed_namespaces List of namespaces where the controller should manage the scale of deployments. The namespaces defined here will be merged with the namespaces fetched by the managed_namespaces_label_selector variable. list(string) [] no
managed_namespaces_all_label_selector Label selector for all resources in the namespaces where the controller should manage the scale of deployments. The namespace must have managed_namespaces_label_selector set. map(string)
{
"sparkfabrik.com/application-availability": "working-hours"
}
no
managed_namespaces_label_selector Label selector for the namespaces where the controller should manage the scale of deployments. The namespaces fetched by this selector will be merged with the managed_namespaces variable. WARNING: remember that if the labels specified here are added to new namespaces, the module will send the Terraform state into drift, as the list of namespaces is retrieved dynamically. You must then re-apply your Terraform configuration to fix the drift.. map(string)
{
"sparkfabrik.com/application-sleep-cycles": "enabled"
}
no
namespace Namespace to create resources. string "application-sleep-cycles" no
protected_namespaces List of namespaces where the controller should not manage the scale of deployments. Use additional_protected_namespaces to add custom protected namespaces. list(string)
[
"kube-node-lease",
"kube-public",
"kube-system",
"gmp-system",
"gmp-public"
]
no
service_account_name Name of the service account. string "application-sleep-cycles-sa" no
statefulsets_label_selector Label selector for the Statefulsets to be scaled during working-hours. map(string)
{
"sparkfabrik.com/application-availability": "working-hours"
}
no
working_hours_docker_image Docker image to use for the working hours CronJobs. string "bitnami/kubectl:1.29" no
working_hours_resource_prefix Prefix for the working hours resources. string "application-sleep-cycles-working-hours" no
working_hours_scale_down_schedule Cron schedule to scale down the Deployments. Remember that this is relative to the timezone defined in the cronjob_timezone variable. string "0 20 * * *" no
working_hours_scale_up_schedule Cron schedule to scale up the Deployments. Remember that this is relative to the timezone defined in the cronjob_timezone variable. string "30 7 * * 1-5" no
working_hours_suspend Suspend the CronJob. bool false no

Outputs

Name Description
k8s_full_labels Full set of labels applied to all resources.
namespace Namespace where the descheduler is installed.

Resources

Name Type
kubernetes_cluster_role_binding_v1.cluster_scoped resource
kubernetes_cluster_role_v1.cluster_scoped resource
kubernetes_config_map_v1.app resource
kubernetes_config_map_v1.app_env resource
kubernetes_manifest.scale_down resource
kubernetes_manifest.scale_up resource
kubernetes_namespace_v1.this resource
kubernetes_secret_v1.this resource
kubernetes_service_account_v1.this resource
kubernetes_namespace_v1.this data source
kubernetes_resources.managed_namespaces_by_labels data source

Modules

No modules.