Home > Blockchain >  How to have multiple host in with Terraform and kubernetes_ingress_v1
How to have multiple host in with Terraform and kubernetes_ingress_v1

Time:09-16

The question is simple, yet I can not find a single example online... basically how do you write this in Terraform with kubernetes_ingress_v1. I basically have an app where I am using subdomains for each of the components due to overlapping paths.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-wildcard-host
spec:
  rules:
  - host: "foo.bar.com"
    http:
      paths:
      - pathType: Prefix
        path: "/bar"
        backend:
          service:
            name: service1
            port:
              number: 80
  - host: "*.foo.com"
    http:
      paths:
      - pathType: Prefix
        path: "/foo"
        backend:
          service:
            name: service2
            port:
              number: 80

CodePudding user response:

With kubernetes_ingress_v1, to have multiple host on same ingress I had to use multiple rule.

resource "kubernetes_ingress_v1" "monitoring" {
  metadata {
    name        = "monitoring-alb"
    namespace   = "monitoring"
    annotations = {
      "kubernetes.io/ingress.class" = "alb"
      #More annotation##
    }
  }
  spec {
    rule {
      host = "monitoring.mydomain.io"
      http {
        path {
          path_type = "ImplementationSpecific"
          backend {
            service {
              name = "grafana"
              port {
                number = 80
              }
            }
          }
        }
      }
    }
    rule {
      host = "logs.mydomain.io"
      http {
        path {
          path_type = "ImplementationSpecific"
          backend {
            service {
              name = "loki-distributed-gateway"
              port {
                number = 80
              }
            }
          }
        }
      }
    }
  }
}
  • Related