From 9b0a912180791b4d800cb64a9d02aed17e6bc305 Mon Sep 17 00:00:00 2001 From: Matteo Vitali Date: Wed, 18 Jan 2023 17:06:20 +0100 Subject: [PATCH] Add k8s deployment resources limits (#40) --- .../modules/kubernetes/deployment/main.tf | 10 ++++++++++ .../kubernetes/deployment/variables.tf | 20 +++++++++++++++++++ .../terraform/vars/.tfvars | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/main.tf b/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/main.tf index cb67e75..bd079ed 100644 --- a/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/main.tf +++ b/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/main.tf @@ -78,6 +78,16 @@ resource "kubernetes_deployment_v1" "main" { container { image = var.service_container_image name = var.service_slug + resources { + requests { + memory = var.service_requests_memory + cpu = var.service_requests_cpu + } + limits { + memory = var.service_limits_memory + cpu = var.service_limits_cpu + } + } port { container_port = var.service_container_port } diff --git a/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/variables.tf b/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/variables.tf index 507f61e..992953b 100644 --- a/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/variables.tf +++ b/{{cookiecutter.project_dirname}}/terraform/modules/kubernetes/deployment/variables.tf @@ -55,12 +55,32 @@ variable "service_container_port" { default = "{{ cookiecutter.internal_service_port }}" } +variable "service_limits_cpu" { + description = "The service limits cpu value." + type = string +} + +variable "service_limits_memory" { + description = "The service limits memory value." + type = string +} + variable "service_replicas" { description = "The desired numbers of replicas to deploy." type = number default = 1 } +variable "service_requests_cpu" { + description = "The service requests cpu value." + type = string +} + +variable "service_requests_memory" { + description = "The service requests memory value." + type = string +} + variable "service_slug" { description = "The service slug." type = string diff --git a/{{cookiecutter.project_dirname}}/terraform/vars/.tfvars b/{{cookiecutter.project_dirname}}/terraform/vars/.tfvars index 3adbef3..9612a23 100644 --- a/{{cookiecutter.project_dirname}}/terraform/vars/.tfvars +++ b/{{cookiecutter.project_dirname}}/terraform/vars/.tfvars @@ -1,3 +1,7 @@ {% if "environment" in cookiecutter.tfvars %}{% for item in cookiecutter.tfvars.environment|sort %}{{ item }} {% endfor %}{% endif %}# service_container_port="{{ cookiecutter.internal_service_port }}" +service_limits_cpu="225m" +service_limits_memory="256Mi" # service_replicas=1 +service_requests_cpu="25m" +service_requests_memory="115Mi"