<p>I am new to K8S and Terraform.  I installed ingress_nginx on K8S Cluster running on Bare-metal.</p>
<pre><code>[root@control02 ~]# kubectl get svc -n ingress-nginx
    NAME                                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
    docker-hello-world-svc               NodePort    10.xx.xx.121     &lt;none&gt;        8086:30333/TCP               13d
    ingress-nginx-controller             NodePort    10.xx.xx.124     &lt;none&gt;        80:31545/TCP,443:30198/TCP   13d
    ingress-nginx-controller-admission   ClusterIP   10.xx.xx.85      &lt;none&gt;        443/TCP                      13d
</code></pre>
<p>I created Deployment, Service and Ingress and am able to access the docker-hello-world-svc from browser successfully.  <strong>Ingress.yaml</strong> is given below</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ing
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
  namespace: ingress-nginx
spec:
  #ingressClassName : nginx
  rules:
  - host: foo.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
           name: docker-hello-world-svc
           port:
            number: 8086
</code></pre>
<p>My requirement is to containerize our PHP based applications on K8S Cluster.</p>
<ol>
<li><p>Creating ingress via <strong>Terraform's</strong> <code>resource &quot;kubernetes_ingress&quot; &quot;web&quot;</code> and <code>ingress.yaml:kubernetes.io/ingress.class</code> are same (or)  are they different?</p>
</li>
<li><p>How can I create 'ingress' on K8S Cluster machine using Terraform ?</p>
<p>For example, when I trigger a job from GitLab, Terraform should create a new <code>&quot;resource kubernetes_ingress&quot;</code> on K8S Cluster or Control-Plane machine.  Is this possible ?</p>
</li>
</ol>
<p>Kindly clarify on the queries mentioned above and let me know if my understanding is wrong</p>

Sathish Kumar
<p>The <code>ingress.class</code> is needed to let the nginx ingress controller understand thathe need to handle this resource.</p>
<p>To create an ingress with terraform you can use the following</p>
<pre><code>resource &quot;kubernetes_ingress&quot; &quot;ingress&quot; {
  metadata {
    name      = &quot;ingress-name&quot;
    namespace = &quot;ingress-namespace&quot;
    labels = {
      app = &quot;some-label-app&quot;
    }
    annotations = {
      &quot;kubernetes.io/ingress.class&quot; : &quot;nginx&quot;
    }
  }

  spec {
    rule {
      host = &quot;foo.com&quot;
      http {
        path {
          backend {
            service_name = &quot;svc&quot;
            service_port = &quot;http&quot;
          }
        }
      }
    }
  }
}
</code></pre>
