From a4a1d55a53548260eb9fb752de214382740a1afd Mon Sep 17 00:00:00 2001 From: shockrah Date: Sun, 8 Dec 2024 18:29:15 -0800 Subject: [PATCH] Dynamically creating the pods/services Allows us configurize everything w/ json later --- infra/vultr-kubernetes/firewall.tf | 5 +-- infra/vultr-kubernetes/game-server.tf | 52 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 infra/vultr-kubernetes/game-server.tf diff --git a/infra/vultr-kubernetes/firewall.tf b/infra/vultr-kubernetes/firewall.tf index f475500..d1fdcab 100644 --- a/infra/vultr-kubernetes/firewall.tf +++ b/infra/vultr-kubernetes/firewall.tf @@ -8,11 +8,12 @@ resource vultr_firewall_rule web_inbound { port = each.value } -resource vultr_firewall_rule web-health-inbound { +resource vultr_firewall_rule game-server-inbound { + for_each = var.game_servers.configs firewall_group_id = vultr_kubernetes.athens.firewall_group_id protocol = "tcp" ip_type = "v4" subnet = "0.0.0.0" subnet_size = 0 - port = local.sanity.port + port = each.value.port } diff --git a/infra/vultr-kubernetes/game-server.tf b/infra/vultr-kubernetes/game-server.tf new file mode 100644 index 0000000..0aee7d2 --- /dev/null +++ b/infra/vultr-kubernetes/game-server.tf @@ -0,0 +1,52 @@ +resource kubernetes_namespace game-servers { + 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 + 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 + } + spec { + selector = { + app = each.key + } + port { + target_port = each.value.port + port = each.value.port + node_port = each.value.port + } + type = "NodePort" + } +}