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
version = var.cluster.version
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 {
cluster_id = vultr_kubernetes.athens.id
node_quantity = var.cluster.pools["games"].min
plan = var.cluster.pools["games"].plan
label = var.game_servers.namespace
min_nodes = var.cluster.pools["games"].min
max_nodes = var.cluster.pools["games"].max
tag = var.game_servers.namespace
node_pools {
node_quantity = var.cluster.pools["main"].min_nodes
plan = var.cluster.pools["main"].plan
label = var.cluster.pools["main"].label
min_nodes = var.cluster.pools["main"].min_nodes
max_nodes = var.cluster.pools["main"].max_nodes
}
}
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
version = string
pools = map(object({
plan = string
autoscale = bool
min = number
max = number
node_quantity = number
plan = string
label = string
min_nodes = number
max_nodes = number
tag = string
}))
})
}
variable game_servers {
type = object({
namespace = string
configs = map(object({
name = optional(string)
image = string
cpu = string
mem = string
port = object({
internal = number
expose = number
})
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)
}))
})
}
# 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 = {
region = "lax"
label = "athens-cluster"
version = "v1.31.2+1"
version = "v1.33.0+1"
pools = {
meta = {
plan = "vc2-1c-2gb"
autoscale = true
min = 1
max = 2
}
games = {
plan = "vc2-1c-2gb"
autoscale = true
min = 1
max = 3
main = {
node_quantity = 1
plan = "vc2-1c-2gb"
label = "main"
min_nodes = 1
max_nodes = 2
tag = "athens-main"
}
}
}
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
}
}
}
}
}