Note
By default, the provider ignores any annotations whose key names end with kubernetes.io. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info: http://kubernetes.io/docs/user-guide/annotations
Note
By default, the provider ignores any labels whose key names end with kubernetes.io. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info: http://kubernetes.io/docs/user-guide/labels
resource "kubernetes_ingress" "example_ingress" {
  metadata {
    name = "example-ingress"
  }
  spec {
    backend {
      service_name = "myapp-1"
      service_port = 8080
    }
    rule {
      http {
        path {
          backend {
            service_name = "myapp-1"
            service_port = 8080
          }
          path = "/app1/*"
        }
        path {
          backend {
            service_name = "myapp-2"
            service_port = 8080
          }
          path = "/app2/*"
        }
      }
    }
    tls {
      secret_name = "tls-secret"
    }
  }
}
resource "kubernetes_service_v1" "example" {
  metadata {
    name = "myapp-1"
  }
  spec {
    selector = {
      app = kubernetes_pod.example.metadata.0.labels.app
    }
    session_affinity = "ClientIP"
    port {
      port        = 8080
      target_port = 80
    }
    type = "NodePort"
  }
}
resource "kubernetes_service_v1" "example2" {
  metadata {
    name = "myapp-2"
  }
  spec {
    selector = {
      app = kubernetes_pod.example2.metadata.0.labels.app
    }
    session_affinity = "ClientIP"
    port {
      port        = 8080
      target_port = 80
    }
    type = "NodePort"
  }
}
resource "kubernetes_pod" "example" {
  metadata {
    name = "terraform-example"
    labels = {
      app = "myapp-1"
    }
  }
  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"
      port {
        container_port = 8080
      }
    }
  }
}
resource "kubernetes_pod" "example2" {
  metadata {
    name = "terraform-example2"
    labels = {
      app = "myapp-2"
    }
  }
  spec {
    container {
      image = "nginx:1.7.9"
      name  = "example"
      port {
        container_port = 8080
      }
    }
  }
}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: my-app.example.com
    http:
      paths:
      - path: /api
        pathType: Prefix
        backend:
          service:
            name: my-app-api
            port:
              name: http
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app-ui
            port:
              name: http
kubectl create -f ingress.yaml
Categorized by Availability, Security & Compliance and Cost