title: Ingress rule using host
body: <p>Can someone please help to spot the issue with <code>ingress-2</code> ingress rule? why <code>ingress-1</code> is working vs <code>ingress-2</code> is not working.</p>
  <p><strong>Description of my setup, I have two deployments:</strong></p>
  <p>1st deployment is of <code>nginx</code><br />
  2nd deployment is of <code>httpd</code></p>
  <p>Both of the deployments are exposed via <code>ClusterIP</code> services named <code>nginx-svc</code> and <code>httpd-svc</code> respectively. All the <code>endpoints</code> are proper for the services. However, while
  setting up the ingress for these services, I am not able to setup the ingress using <code>host</code> (as described in <code>ingress-2</code>). however, when I am using <code>ingress-1</code>, things work fine.</p>
  <p>// my host file for name resolution</p>
  <pre><code>grep myapp.com /etc/hosts
  127.0.0.1        myapp.com
  </code></pre>
  <p>// deployment details</p>
  <pre><code>kubectl get deployments.apps
  NAME    READY   UP-TO-DATE   AVAILABLE   AGE
  nginx   3/3     3            3           29m
  httpd   3/3     3            3           29m
  </code></pre>
  <p>// service details</p>
  <pre><code>kubectl get svc
  NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
  kubernetes   ClusterIP   10.152.183.1     &lt;none&gt;        443/TCP   7h48m
  nginx-svc    ClusterIP   10.152.183.233   &lt;none&gt;        80/TCP    28m
  httpd-svc    ClusterIP   10.152.183.58    &lt;none&gt;        80/TCP    27m
  </code></pre>
  <p>// endpoints details</p>
  <pre><code>kubectl get ep
  NAME         ENDPOINTS                                      AGE
  kubernetes   10.0.2.15:16443                                7h51m
  nginx-svc    10.1.198.86:80,10.1.198.87:80,10.1.198.88:80   31m
  httpd-svc    10.1.198.89:80,10.1.198.90:80,10.1.198.91:80   31m
  </code></pre>
  <p>Attempt-1: <code>ingress-1</code></p>
  <pre><code>apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: ingress-1
  spec:
    rules:
    - http:
        paths:
        - path: /nginx
          pathType: Prefix
          backend:
            service:
              name: nginx-svc
              port:
                number: 80
  
        - path: /httpd
          pathType: Prefix
          backend:
            service:
              name: httpd-svc
              port:
                number: 80
  </code></pre>
  <p>// Example showing that ingress routing is working fine when <code>ingress-1</code> is used:</p>
  <pre><code> curl myapp.com/nginx
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Welcome to nginx!&lt;/title&gt;
  &lt;style&gt;
      body {
          width: 35em;
          margin: 0 auto;
          font-family: Tahoma, Verdana, Arial, sans-serif;
      }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Welcome to nginx!&lt;/h1&gt;
  &lt;p&gt;If you see this page, the nginx web server is successfully installed and
  working. Further configuration is required.&lt;/p&gt;
  
  &lt;p&gt;For online documentation and support please refer to
  &lt;a href=&quot;http://nginx.org/&quot;&gt;nginx.org&lt;/a&gt;.&lt;br/&gt;
  Commercial support is available at
  &lt;a href=&quot;http://nginx.com/&quot;&gt;nginx.com&lt;/a&gt;.&lt;/p&gt;
  
  &lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;/em&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
   curl myapp.com/httpd
  &lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  <p>// following ingress rule is not working as I was expecting</p>
  <p>Attempt-2: <code>ingress-2</code></p>
  <pre><code>kind: Ingress
  metadata:
    name: ingress-2
  spec:
    rules:
    - host: &quot;myapp.com&quot;
      http:
        paths:
        - pathType: Prefix
          path: &quot;/nginx&quot;
          backend:
            service:
              name: nginx-svc
              port:
                number: 80
        - pathType: Prefix
          path: &quot;/httpd&quot;
          backend:
            service:
              name: httpd-svc
              port:
                number: 80
  </code></pre>
  <p>// I could not spot any issue in the ing describe</p>
  <pre><code>kubectl describe  ingress ingress-2
  Name:             ingress-2
  Namespace:        default
  Address:          127.0.0.1
  Default backend:  default-http-backend:80 (&lt;error: endpoints &quot;default-http-backend&quot; not found&gt;)
  Rules:
    Host          Path  Backends
    ----          ----  --------
    myapp.com
                  /nginx   nginx-svc:80 (10.1.198.86:80,10.1.198.87:80,10.1.198.88:80)
                  /httpd   httpd-svc:80 (10.1.198.89:80,10.1.198.90:80,10.1.198.91:80)
  Annotations:    &lt;none&gt;
  Events:
    Type    Reason  Age                  From                      Message
    ----    ------  ----                 ----                      -------
    Normal  Sync    9m15s (x2 over 10m)  nginx-ingress-controller  Scheduled for sync
  </code></pre>
  <p>// example showing ingress routing is not working with this ingress resource</p>
  <pre><code>curl myapp.com/nginx
  &lt;html&gt;
  &lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;center&gt;&lt;h1&gt;404 Not Found&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;nginx/1.21.1&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  curl myapp.com/httpd
  &lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;404 Not Found&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Not Found&lt;/h1&gt;
  &lt;p&gt;The requested URL was not found on this server.&lt;/p&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>