<p>I want to organize my web apis iwth kubernetes ingress tool.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp-api-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    # nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    # nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: api.myapp.com
    http:
      paths:
      - pathType: Prefix
        path: /catalog
        backend:
          service:
            name: myapp-catalog-service
            port: 
              number: 80
      - pathType: Prefix
        path: /identity
        backend:
          service:
            name: myapp-identity-service
            port: 
              number: 80
</code></pre>
<p>With this configuration, I can access the &quot;<code>api.myapp.com/catalog</code>&quot;.</p>
<p>But &quot;<code>api.myapp.com/catalog</code>&quot; is 404 not found. How can fix this configuration?</p>

barteloma
<p>Seems to be an issue with rewrite annotation that might cause the 404 error.  Can you give the below annotation in the yaml and give a try :</p>
<pre><code> nginx.ingress.kubernetes.io/rewrite-target: /$2
</code></pre>
<p>As per this rewrite <a href="https://github.com/kubernetes/ingress-nginx/tree/main/docs/examples/rewrite" rel="nofollow noreferrer">target example</a> , These $2 placeholders can be used as parameters in the rewrite-target annotation. This Target URI where the traffic must be redirected.</p>
<p>As per Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#simple-fanout" rel="nofollow noreferrer">ingress</a> update your yaml as below example which can be accessed from  foo.bar.com/foo from port 4200 and foo.bar.com/bar from port 8080.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: simple-fanout-example
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foo
        pathType: Prefix
        backend:
          service:
            name: service1
            port:
              number: 4200
      - path: /bar
        pathType: Prefix
        backend:
          service:
            name: service2
            port:
              number: 8080
    
</code></pre>
<p>Refer to this <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/" rel="nofollow noreferrer">ingress path matching doc</a> and <a href="https://stackoverflow.com/questions/56942594/kubernetes-ingress-gives-404-error-for-a-particular-service">SO</a></p>
