<p>I'm using <code>Kubernetes v1.23.16 cluster (One master and three workers)</code> bare metal based.</p>
<p>I have created couple of services in a separate namespace. The same as follows.</p>
<pre><code>$ kubectl get services --all-namespaces
NAMESPACE     NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default       kubernetes        ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP                  11d
app1          app1-service      ClusterIP   10.103.151.235   &lt;none&gt;        80/TCP                   19h
app2          app2-service      ClusterIP   10.105.88.151    &lt;none&gt;        80/TCP                   11d
kube-system   kube-dns          ClusterIP   10.96.0.10       &lt;none&gt;        53/UDP,53/TCP,9153/TCP   11d
</code></pre>
<p>Now I'm having below <code>nginx resource yml</code> to access the service outside. For example i would like access as given below.</p>
<ol>
<li><a href="http://web.example.com/app1" rel="nofollow noreferrer">http://web.example.com/app1</a></li>
<li><a href="http://web.example.com/app2" rel="nofollow noreferrer">http://web.example.com/app2</a></li>
</ol>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: app-ingress
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-service
            port: 
              number: 80

      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-service
            port:
              number: 80
</code></pre>
<p>When i apply the <code>nginx resource yml</code> file it says <code>service not found</code> error.</p>
<pre><code>$ kubectl describe ingress app-ingress
Name:             app-ingress
Labels:           &lt;none&gt;
Namespace:        default
Address:
Default backend:  default-http-backend:80 (&lt;error: endpoints &quot;default-http-backend&quot; not found&gt;)
Rules:
  Host             Path  Backends
  ----             ----  --------
  web.example.com
                   /app1    app1-service:80 (&lt;error: endpoints &quot;app1-service&quot; not found&gt;)
                   /app2    app2-service:80 (&lt;error: endpoints &quot;app2-service&quot; not found&gt;)
Annotations:       nginx.ingress.kubernetes.io/rewrite-target: /$2
</code></pre>
<p>Since my applications services are running in different namespace separately and my <code>nginx resource yml</code> is running in <code>default</code> namespace. So now how do i configure nginx resource file to access both of my service?</p>

user4948798
<p>An Ingress resource can only refer to Services in the same namespace as the Ingress. To manage two paths on the same hostname that lead to backends in different namespaces, you will need two separate Ingress resources.</p>
<p>In the <code>app1</code> namespace:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  namespace: app1
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-service
            port:
              number: 80
</code></pre>
<p>And in the <code>app2</code> namespace:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  namespace: app2
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-service
            port:
              number: 80
</code></pre>
<p>With these resources in place, requests for <a href="http://web.example.com/app1" rel="nofollow noreferrer">http://web.example.com/app1</a> will go to app1-service, and requests for <a href="http://web.example.com/app2" rel="nofollow noreferrer">http://web.example.com/app2</a> will go to app2-service.</p>
<p>NB: I've removed your <code>nginx.ingress.kubernetes.io/rewrite-target</code> annotation because you're not doing any regex-based path rewriting in this example.</p>
<hr />
<p>I've put a deployable example online <a href="https://github.com/larsks/so-example-75417732-one-host-two-apps" rel="nofollow noreferrer">here</a>.</p>
