From 18d9698f295bab7b9e57db9426c55e425f0a1358 Mon Sep 17 00:00:00 2001 From: haroldsphinx Date: Tue, 7 Nov 2023 13:44:58 +0100 Subject: [PATCH 1/4] Update ingress controller Signed-off-by: haroldsphinx --- deployment.tf | 2 +- lb-service.tf | 31 +++++++++++++++++++++++++++++++ service.tf | 23 ----------------------- variables.tf | 43 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 lb-service.tf delete mode 100644 service.tf diff --git a/deployment.tf b/deployment.tf index 9789b0a..d15d757 100644 --- a/deployment.tf +++ b/deployment.tf @@ -84,7 +84,7 @@ resource "kubernetes_deployment" "nginx_ingress" { "/nginx-ingress-controller", "--configmap=$(POD_NAMESPACE)/${kubernetes_config_map.nginx_ingress.metadata.0.name}", "--publish-service=$(POD_NAMESPACE)/${kubernetes_service.nginx_ingress.metadata.0.name}", - "--election-id=${local.app_name}-leader", + "--election-id=ingress-controller-leader", "--ingress-class=nginx" ] security_context { diff --git a/lb-service.tf b/lb-service.tf new file mode 100644 index 0000000..ed2fd3c --- /dev/null +++ b/lb-service.tf @@ -0,0 +1,31 @@ +resource "kubernetes_service" "nginx_ingress" { + metadata { + name = local.app_name + namespace = data.kubernetes_namespace.ns.metadata.0.name + + labels = local.labels + + annotations = var.lb_annotations + } + + spec { + type = "LoadBalancer" + selector = { + "app.kubernetes.io/name" = local.app_name + "app.kubernetes.io/part-of" = data.kubernetes_namespace.ns.metadata.0.name + } + + external_traffic_policy = "Cluster" + + dynamic "port" { + for_each = var.lb_ports + + content { + name = port.value.name + port = port.value.port + target_port = port.value.target_port + } + } + load_balancer_source_ranges = var.load_balancer_source_ranges + } +} \ No newline at end of file diff --git a/service.tf b/service.tf deleted file mode 100644 index 624b74c..0000000 --- a/service.tf +++ /dev/null @@ -1,23 +0,0 @@ -resource "kubernetes_service" "nginx_ingress" { - metadata { - name = local.app_name - namespace = data.kubernetes_namespace.ns.metadata.0.name - labels = local.labels - } - - spec { - selector = local.labels - - port { - name = "http" - port = 80 - target_port = "http" - } - - port { - name = "https" - port = 443 - target_port = "https" - } - } -} diff --git a/variables.tf b/variables.tf index 0a2c858..4516d36 100644 --- a/variables.tf +++ b/variables.tf @@ -49,7 +49,7 @@ variable "nginx_extra_response_headers" { variable "nginx_image" { description = "Nginx container image" type = string - default = "k8s.gcr.io/ingress-nginx/controller:v1.0.3" + default = "registry.k8s.io/ingress-nginx/controller:v1.2.1@sha256:5516d103a9c2ecc4f026efbd4b40662ce22dc1f824fb129ed121460aaa5c47f8" } variable "nginx_resources" { @@ -93,4 +93,45 @@ variable "priority_class_name" { description = "The priority class to attach to the deployment" type = string default = null +} + +variable "lb_annotations" { + description = "Annotations to add to the loadbalancer" + type = map(string) + default = { + "service.beta.kubernetes.io/aws-load-balancer-type" = "nlb" + "service.beta.kubernetes.io/aws-load-balancer-scheme" = "internet-facing" + "service.beta.kubernetes.io/aws-load-balancer-name" = "blockops-testnet-lb" + "service.beta.kubernetes.io/aws-load-balancer-nlb-target-type" = "ip" + "service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled" = "true" + "service.beta.kubernetes.io/aws-load-balancer-name" = "blockops-testnet-lb" + "service.beta.kubernetes.io/aws-load-balancer-subnets" = "subnet-00b8b96e244c4ca11, subnet-0b45c2527c341933b, subnet-0efc0704ddd82d424" + "service.beta.kubernetes.io/aws-load-balancer-ssl-ports" = "443" + "service.beta.kubernetes.io/load-balancer-source-ranges" = "0.0.0.0/0" + + } +} + +variable "load_balancer_source_ranges" { + description = "The ip whitelist that is allowed to access the load balancer" + default = ["0.0.0.0/0"] + type = list(string) +} + +variable "lb_ports" { + description = "Load balancer port configuration" + type = list(object({ + name = string + port = number + target_port = string + })) + default = [{ + name = "http" + port = 80 + target_port = "http" + }, { + name = "https" + port = 443 + target_port = "https" + }] } \ No newline at end of file From 5ec582dec9783f2aee79ba18b1ec56f6ae1811b1 Mon Sep 17 00:00:00 2001 From: haroldsphinx Date: Tue, 7 Nov 2023 13:50:57 +0100 Subject: [PATCH 2/4] Update ingress controller Signed-off-by: haroldsphinx --- lb-service.tf | 31 ------------------------------- service.tf | 23 +++++++++++++++++++++++ variables.tf | 41 ----------------------------------------- 3 files changed, 23 insertions(+), 72 deletions(-) delete mode 100644 lb-service.tf create mode 100644 service.tf diff --git a/lb-service.tf b/lb-service.tf deleted file mode 100644 index ed2fd3c..0000000 --- a/lb-service.tf +++ /dev/null @@ -1,31 +0,0 @@ -resource "kubernetes_service" "nginx_ingress" { - metadata { - name = local.app_name - namespace = data.kubernetes_namespace.ns.metadata.0.name - - labels = local.labels - - annotations = var.lb_annotations - } - - spec { - type = "LoadBalancer" - selector = { - "app.kubernetes.io/name" = local.app_name - "app.kubernetes.io/part-of" = data.kubernetes_namespace.ns.metadata.0.name - } - - external_traffic_policy = "Cluster" - - dynamic "port" { - for_each = var.lb_ports - - content { - name = port.value.name - port = port.value.port - target_port = port.value.target_port - } - } - load_balancer_source_ranges = var.load_balancer_source_ranges - } -} \ No newline at end of file diff --git a/service.tf b/service.tf new file mode 100644 index 0000000..896f1bc --- /dev/null +++ b/service.tf @@ -0,0 +1,23 @@ +resource "kubernetes_service" "nginx_ingress" { + metadata { + name = local.app_name + namespace = data.kubernetes_namespace.ns.metadata.0.name + labels = local.labels + } + + spec { + selector = local.labels + + port { + name = "http" + port = 80 + target_port = "http" + } + + port { + name = "https" + port = 443 + target_port = "https" + } + } +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 4516d36..7b61e80 100644 --- a/variables.tf +++ b/variables.tf @@ -93,45 +93,4 @@ variable "priority_class_name" { description = "The priority class to attach to the deployment" type = string default = null -} - -variable "lb_annotations" { - description = "Annotations to add to the loadbalancer" - type = map(string) - default = { - "service.beta.kubernetes.io/aws-load-balancer-type" = "nlb" - "service.beta.kubernetes.io/aws-load-balancer-scheme" = "internet-facing" - "service.beta.kubernetes.io/aws-load-balancer-name" = "blockops-testnet-lb" - "service.beta.kubernetes.io/aws-load-balancer-nlb-target-type" = "ip" - "service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled" = "true" - "service.beta.kubernetes.io/aws-load-balancer-name" = "blockops-testnet-lb" - "service.beta.kubernetes.io/aws-load-balancer-subnets" = "subnet-00b8b96e244c4ca11, subnet-0b45c2527c341933b, subnet-0efc0704ddd82d424" - "service.beta.kubernetes.io/aws-load-balancer-ssl-ports" = "443" - "service.beta.kubernetes.io/load-balancer-source-ranges" = "0.0.0.0/0" - - } -} - -variable "load_balancer_source_ranges" { - description = "The ip whitelist that is allowed to access the load balancer" - default = ["0.0.0.0/0"] - type = list(string) -} - -variable "lb_ports" { - description = "Load balancer port configuration" - type = list(object({ - name = string - port = number - target_port = string - })) - default = [{ - name = "http" - port = 80 - target_port = "http" - }, { - name = "https" - port = 443 - target_port = "https" - }] } \ No newline at end of file From c8867f9d16840fecad551949b1ce9d76d809895e Mon Sep 17 00:00:00 2001 From: haroldsphinx Date: Tue, 7 Nov 2023 13:52:01 +0100 Subject: [PATCH 3/4] Update ingress controller Signed-off-by: haroldsphinx --- providers.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers.tf b/providers.tf index 39a878b..43f5244 100644 --- a/providers.tf +++ b/providers.tf @@ -5,7 +5,7 @@ terraform { required_providers { kubernetes = { source = "hashicorp/kubernetes" - version = ">= 2.10" + version = "~> 2.3.2" } } } From e865170ffbd59b325788cb4126a33acd7f866847 Mon Sep 17 00:00:00 2001 From: haroldsphinx Date: Tue, 7 Nov 2023 13:53:25 +0100 Subject: [PATCH 4/4] Update ingress controller Signed-off-by: haroldsphinx --- providers.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers.tf b/providers.tf index 43f5244..c32c2a8 100644 --- a/providers.tf +++ b/providers.tf @@ -5,7 +5,7 @@ terraform { required_providers { kubernetes = { source = "hashicorp/kubernetes" - version = "~> 2.3.2" + version = ">= 2.3.2" } } }