Slimming down the cluster definition
Some checks failed
Ansible Linting / ansible-lint (push) Failing after 5s
Secops Linting and Safety Checks / checkov-scan-s3 (push) Failing after 16s

This commit is contained in:
shockrah 2025-05-28 18:24:31 -07:00
parent 88059a5e0f
commit ee2d502ca6
4 changed files with 39 additions and 149 deletions

View File

@ -2,27 +2,14 @@ resource vultr_kubernetes athens {
region = var.cluster.region region = var.cluster.region
version = var.cluster.version version = var.cluster.version
label = var.cluster.label label = var.cluster.label
# BUG: only have this set when creating the resource for the first time
# once the cluster is up, we should comment this out again
# enable_firewall = true
node_pools {
node_quantity = 1
plan = var.cluster.pools["meta"].plan
label = var.admin_services.namespace
min_nodes = var.cluster.pools["meta"].min
max_nodes = var.cluster.pools["meta"].max
# tag = var.admin_services.namespace
}
}
resource vultr_kubernetes_node_pools games { node_pools {
cluster_id = vultr_kubernetes.athens.id node_quantity = var.cluster.pools["main"].min_nodes
node_quantity = var.cluster.pools["games"].min plan = var.cluster.pools["main"].plan
plan = var.cluster.pools["games"].plan label = var.cluster.pools["main"].label
label = var.game_servers.namespace min_nodes = var.cluster.pools["main"].min_nodes
min_nodes = var.cluster.pools["games"].min max_nodes = var.cluster.pools["main"].max_nodes
max_nodes = var.cluster.pools["games"].max }
tag = var.game_servers.namespace
} }
output k8s_config { output k8s_config {

View File

@ -1,55 +0,0 @@
resource kubernetes_namespace game-servers {
count = length(var.game_servers.configs) > 0 ? 1 : 0
metadata {
name = var.game_servers.namespace
}
}
resource kubernetes_pod game {
for_each = var.game_servers.configs
metadata {
name = each.key
namespace = var.game_servers.namespace
labels = {
app = each.key
}
}
spec {
container {
image = each.value.image
name = coalesce(each.value.name, each.key)
resources {
limits = {
cpu = each.value.cpu
memory = each.value.mem
}
}
port {
container_port = each.value.port.internal
protocol = coalesce(each.value.proto, "TCP")
}
}
}
}
resource kubernetes_service game {
for_each = var.game_servers.configs
metadata {
name = each.key
namespace = var.game_servers.namespace
labels = {
app = each.key
}
}
spec {
selector = {
app = each.key
}
port {
target_port = each.value.port.internal
port = each.value.port.expose
}
type = "NodePort"
}
}

View File

@ -26,46 +26,31 @@ variable cluster {
label = string label = string
version = string version = string
pools = map(object({ pools = map(object({
plan = string node_quantity = number
autoscale = bool plan = string
min = number label = string
max = number min_nodes = number
max_nodes = number
tag = string
})) }))
}) })
} }
variable game_servers { # variable admin_services {
type = object({ # type = object({
namespace = string # namespace = string
configs = map(object({ # configs = map(object({
name = optional(string) # name = string
image = string # image = string
cpu = string # cpu = string
mem = string # mem = string
port = object({ # port = object({
internal = number # notes = optional(string)
expose = number # internal = number
}) # expose = number
proto = optional(string) # })
})) # proto = optional(string)
}) # }))
} # })
# }
variable admin_services {
type = object({
namespace = string
configs = map(object({
name = string
image = string
cpu = string
mem = string
port = object({
notes = optional(string)
internal = number
expose = number
})
proto = optional(string)
}))
})
}

View File

@ -1,42 +1,15 @@
cluster = { cluster = {
region = "lax" region = "lax"
label = "athens-cluster" label = "athens-cluster"
version = "v1.31.2+1" version = "v1.33.0+1"
pools = { pools = {
meta = { main = {
plan = "vc2-1c-2gb" node_quantity = 1
autoscale = true plan = "vc2-1c-2gb"
min = 1 label = "main"
max = 2 min_nodes = 1
} max_nodes = 2
games = { tag = "athens-main"
plan = "vc2-1c-2gb"
autoscale = true
min = 1
max = 3
}
}
}
game_servers = {
namespace = "games"
configs = {
}
}
admin_services = {
namespace = "admin-services"
configs = {
health = {
image = "nginx:latest"
name = "health"
cpu = "200m"
mem = "64Mi"
port = {
notes = "Basic nginx sanity check service"
expose = 30800
internal = 80
}
} }
} }
} }