terraform kubernetes provider: namespace destination

5/22/2020

I'm creating an ingress using terraform kubernetes_ingress resource:

resource "kubernetes_ingress" "this" {
    metadata {
        name = "mongodb-ingress"
    }

    spec {
        backend {
            service_name = "mongodb"
            service_port = 9092
        }

        rule {
            http {
                path {
                    path = "/mongodb/*"
                    backend {
                        service_name = "mongodb"
                        service_port = 9092
                    }
                }
            }
        }
    }
}

It's not clear to me which namespace will be assigned this ingress rule on.

I've tried to get if there's any namespace property, but I don't quite figure out where is it.

Any ideas?

-- Jordi
terraform
terraform-provider-kubernetes

1 Answer

5/22/2020

There is a namespace property in terraform kubernetes provider. Please take a loot at here.

If you don't specify a namespace then it'll be created in default namespace.

resource "kubernetes_ingress" "this" {
    metadata {
        name = "mongodb-ingress"
        namespace = "dev"
    }

    spec {
        backend {
            service_name = "mongodb"
            service_port = 9092
        }

        rule {
            http {
                path {
                    path = "/mongodb/*"
                    backend {
                        service_name = "mongodb"
                        service_port = 9092
                    }
                }
            }
        }
    }
}

kubectl get ing -n dev
NAME              CLASS    HOSTS   ADDRESS   PORTS   AGE
mongodb-ingress   <none>   *                 80      7s
-- hariK
Source: StackOverflow