diff --git a/terraform/deployment.tf b/terraform/deployment.tf index f13f361..4ef03a3 100644 --- a/terraform/deployment.tf +++ b/terraform/deployment.tf @@ -6,7 +6,7 @@ data "kubernetes_namespace" "app" { resource "kubernetes_secret" "app" { metadata { - name = "api" + name = "compactdisc" namespace = var.namespace } @@ -28,3 +28,93 @@ resource "kubernetes_secret" "app" { }) } } + +resource "kubernetes_deployment" "app" { + metadata { + name = "compactdisc" + namespace = data.kubernetes_namespace.app.metadata[0].name + labels = { + app = "compactdisc" + } + } + + spec { + selector { + match_labels = { + app = "compactdisc" + } + } + + strategy { + type = "RollingUpdate" + rolling_update { + max_surge = "0" + max_unavailable = "1" + } + } + + template { + metadata { + labels = { + app = "compactdisc" + } + } + + spec { + container { + name = "compactdisc" + image = local.image_url + + resources { + requests = { + memory = "384Mi" + cpu = "200m" + } + limits = { + memory = "384Mi" + cpu = "200m" + } + } + + port { + name = "api" + container_port = 3000 + protocol = "TCP" + } + + volume_mount { + name = "config" + mount_path = "/app/config.yaml" + sub_path = "config.yaml" + } + } + + volume { + name = "config" + secret { + secret_name = kubernetes_secret.app.metadata[0].name + } + } + } + } + } +} + +resource "kubernetes_service" "app" { + metadata { + name = "compactdisc" + namespace = data.kubernetes_namespace.app.metadata[0].name + } + + spec { + selector = { + app = "compactdisc" + } + + port { + name = "api" + port = 3000 + target_port = "api" + } + } +}