Project: KICS (Provisioning / Security & Compliance)
File: 5f4735ce-b9ba-4d95-a089-a37a767b716f.md

title: CPU Limits Not Set hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 5f4735ce-b9ba-4d95-a089-a37a767b716f Query name: CPU Limits Not Set Platform: Terraform Severity: <span style="color:#edd57e">Low</span> Category: Resource Management URL: CPU limits should be set because if the system has CPU time free, a container is guaranteed to be allocated as much CPU as it requests<br> ```tf title="Positive test num. 1 - tf file" hl_lines="8 106" resource "kubernetes_pod" "positive1" { metadata { name = "terraform-example" } spec { container = [ { image = "nginx:1.7.9" name = "example22" env = { name = "environment" value = "test" } port = { container_port = 8080 } liveness_probe = { http_get = { path = "/nginx_status" port = 80 http_header = { name = "X-Custom-Header" value = "Awesome" } } initialdelayseconds = 3 period_seconds = 3 } } , { image = "nginx:1.7.9" name = "example22222" resources = { requests = { memory = "50Mi" } } env = { name = "environment" value = "test" } port = { container_port = 8080 } liveness_probe = { http_get = { path = "/nginx_status" port = 80 http_header = { name = "X-Custom-Header" value = "Awesome" } } initialdelayseconds = 3 period_seconds = 3 } } ] dns_config { nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] searches = ["example.com"] option { name = "ndots" value = 1 } option { name = "use-vc" } } dns_policy = "None" } } resource "kubernetes_pod" "positive2" { metadata { name = "terraform-example" } spec { container { image = "nginx:1.7.9" name = "example" resources { limits { memory = "512Mi" } } env { name = "environment" value = "test" } port { container_port = 8080 } liveness_probe { http_get { path = "/nginx_status" port = 80 http_header { name = "X-Custom-Header" value = "Awesome" } } initialdelayseconds = 3 period_seconds = 3 } } dns_config { nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] searches =

option { name = "ndots" value = 1 } option { name = "use-vc" } } dns_policy = "None" } } ``` ```tf title="Negative test num. 1 - tf file" resource "kubernetes_pod" "negative1" { metadata { name = "terraform-example" } spec { container = [ { image = "nginx:1.7.9" name = "example22" resources = { limits = { cpu = "0.5" memory = "512Mi" } requests = { cpu = "250m" memory = "50Mi" } } env = { name = "environment" value = "test" } port = { container_port = 8080 } liveness_probe = { http_get = { path = "/nginx_status" port = 80 http_header = { name = "X-Custom-Header" value = "Awesome" } } initialdelayseconds = 3 period_seconds = 3 } } , { image = "nginx:1.7.9" name = "example22222" resources = { limits = { cpu = "0.5" memory = "512Mi" } requests = { cpu = "250m" memory = "50Mi" } } env = { name = "environment" value = "test" } port = { container_port = 8080 } liveness_probe = { http_get = { path = "/nginx_status" port = 80 http_header = { name = "X-Custom-Header" value = "Awesome" } } initialdelayseconds = 3 period_seconds = 3 } } ] dns_config { nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] searches = ["example.com"] option { name = "ndots" value = 1 } option { name = "use-vc" } } dns_policy = "None" } } resource "kubernetes_pod" "negative2" { metadata { name = "terraform-example" } spec { container { image = "nginx:1.7.9" name = "example" resources { limits { cpu = "0.5" memory = "512Mi" } requests { cpu = "250m" memory = "50Mi" } } env { name = "environment" value = "test" } port { container_port = 8080 } liveness_probe { http_get { path = "/nginx_status" port = 80 http_header { name = "X-Custom-Header" value = "Awesome" } } initialdelayseconds = 3 period_seconds = 3 } } dns_config { nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] searches = ["example.com"] option { name = "ndots" value = 1 } option { name = "use-vc" } } dns_policy = "None" } } ```