diff --git a/infra/vultr-kubernetes/firewall.tf b/infra/vultr-kubernetes/firewall.tf index d1fdcab..ff296f8 100644 --- a/infra/vultr-kubernetes/firewall.tf +++ b/infra/vultr-kubernetes/firewall.tf @@ -15,5 +15,5 @@ resource vultr_firewall_rule game-server-inbound { ip_type = "v4" subnet = "0.0.0.0" subnet_size = 0 - port = each.value.port + port = each.value.port.expose } diff --git a/infra/vultr-kubernetes/game-server.tf b/infra/vultr-kubernetes/game-server.tf index 0aee7d2..4776f1a 100644 --- a/infra/vultr-kubernetes/game-server.tf +++ b/infra/vultr-kubernetes/game-server.tf @@ -25,7 +25,7 @@ resource kubernetes_pod game { } } port { - container_port = each.value.port + container_port = each.value.port.internal protocol = coalesce(each.value.proto, "TCP") } } @@ -37,15 +37,17 @@ resource kubernetes_service game { metadata { name = each.key namespace = var.game_servers.namespace + labels = { + app = each.key + } } spec { selector = { app = each.key } port { - target_port = each.value.port - port = each.value.port - node_port = each.value.port + target_port = each.value.port.internal + port = each.value.port.expose } type = "NodePort" } diff --git a/infra/vultr-kubernetes/variables.tf b/infra/vultr-kubernetes/variables.tf index 0e1ba9a..31e7a94 100644 --- a/infra/vultr-kubernetes/variables.tf +++ b/infra/vultr-kubernetes/variables.tf @@ -42,7 +42,10 @@ variable game_servers { image = string cpu = string mem = string - port = number + port = object({ + internal = number + expose = number + }) proto = optional(string) }) ) diff --git a/infra/vultr-kubernetes/variables.tfvars b/infra/vultr-kubernetes/variables.tfvars index f42af49..fee2267 100644 --- a/infra/vultr-kubernetes/variables.tfvars +++ b/infra/vultr-kubernetes/variables.tfvars @@ -17,7 +17,10 @@ game_servers = { image = "nginx:latest" cpu = "200m" mem = "64Mi" - port = 30808 + port = { + expose = 30808 + internal = 80 + } } } } \ No newline at end of file