From f2c4506245178b31153d2755dea704fdb953ddf8 Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 19 Dec 2024 01:28:44 -0800 Subject: [PATCH] separating game and admin service node pools with pods and what not --- infra/vultr-kubernetes/admin-services.tf | 4 +++ infra/vultr-kubernetes/cluster.tf | 20 +++++++++--- infra/vultr-kubernetes/game-server.tf | 1 + infra/vultr-kubernetes/variables.tf | 23 +++++++------- infra/vultr-kubernetes/variables.tfvars | 40 ++++++++++++++---------- 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/infra/vultr-kubernetes/admin-services.tf b/infra/vultr-kubernetes/admin-services.tf index d6b53d4..18addc7 100644 --- a/infra/vultr-kubernetes/admin-services.tf +++ b/infra/vultr-kubernetes/admin-services.tf @@ -1,4 +1,5 @@ resource kubernetes_namespace admin-servers { + count = length(var.admin_services.configs) > 0 ? 1 : 0 metadata { name = var.admin_services.namespace } @@ -15,6 +16,9 @@ resource kubernetes_pod admin { } } spec { + node_selector = { + NodeType = var.admin_services.namespace + } container { image = each.value.image name = coalesce(each.value.name, each.key) diff --git a/infra/vultr-kubernetes/cluster.tf b/infra/vultr-kubernetes/cluster.tf index 1e0700a..dc9f1bd 100644 --- a/infra/vultr-kubernetes/cluster.tf +++ b/infra/vultr-kubernetes/cluster.tf @@ -6,15 +6,25 @@ resource vultr_kubernetes athens { # once the cluster is up, we should comment this out again # enable_firewall = true node_pools { - # how many nodes do we want in this pool node_quantity = 1 - plan = var.cluster.metapool.plan - label = var.cluster.label - min_nodes = var.cluster.metapool.min - max_nodes = var.cluster.metapool.max + 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.admin_services.namespace +} + output k8s_config { value = vultr_kubernetes.athens.kube_config sensitive = true diff --git a/infra/vultr-kubernetes/game-server.tf b/infra/vultr-kubernetes/game-server.tf index 4776f1a..0d97063 100644 --- a/infra/vultr-kubernetes/game-server.tf +++ b/infra/vultr-kubernetes/game-server.tf @@ -1,4 +1,5 @@ resource kubernetes_namespace game-servers { + count = length(var.game_servers.configs) > 0 ? 1 : 0 metadata { name = var.game_servers.namespace } diff --git a/infra/vultr-kubernetes/variables.tf b/infra/vultr-kubernetes/variables.tf index fdeffc4..d032ac4 100644 --- a/infra/vultr-kubernetes/variables.tf +++ b/infra/vultr-kubernetes/variables.tf @@ -25,12 +25,12 @@ variable cluster { region = string label = string version = string - metapool = object({ + pools = map(object({ plan = string autoscale = bool min = number max = number - }) + })) }) } @@ -38,17 +38,16 @@ 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) + name = optional(string) + image = string + cpu = string + mem = string + port = object({ + internal = number + expose = number }) - ) + proto = optional(string) + })) }) } diff --git a/infra/vultr-kubernetes/variables.tfvars b/infra/vultr-kubernetes/variables.tfvars index 75011ff..2a74640 100644 --- a/infra/vultr-kubernetes/variables.tfvars +++ b/infra/vultr-kubernetes/variables.tfvars @@ -2,11 +2,19 @@ cluster = { region = "lax" label = "athens-cluster" version = "v1.31.2+1" - metapool = { - plan = "vc2-1c-2gb" - autoscale = true - min = 1 - max = 2 + pools = { + meta = { + plan = "vc2-1c-2gb" + autoscale = true + min = 1 + max = 2 + } + games = { + plan = "vc2-1c-2gb" + autoscale = true + min = 1 + max = 3 + } } } @@ -28,16 +36,16 @@ game_servers = { 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 - } - } + # health = { + # image = "nginx:latest" + # name = "health" + # cpu = "200m" + # mem = "64Mi" + # port = { + # notes = "Basic nginx sanity check service" + # expose = 30800 + # internal = 80 + # } + # } } }