<p>I have multiple APIs all listening on '/api' and a web front end listening on '/'.</p>

<p>Is there a way which I can write my ingress definition to rewrite the paths to something like the following?</p>

<pre><code>/api/      -&gt; /api/ on service1
/api2/api/ -&gt; /api/ on service2
/api3/api/ -&gt; /api/ on service3
/          -&gt; /     on service4
</code></pre>

<p>I know I can change the APIs to listen to something else but don't want to do that. I know I can also just rewrite all to /api/ and let service3 act as the default but there may be other services which need routing elsewhere in the future.</p>

<p>I've heard that you could use multiple ingresses but I'm not sure how that would affect performance and if it's best practice to do so.</p>

<p>Also, is there any way to debug which route goes to which service?</p>

<p>Thanks,
James</p>

<p>With help from @Rahman - see other answer. I've managed to get this to work with a single ingress.</p>

<p>I've had to post this as an additional answer because of the character limit.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-name
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  tls:
  - secretName: tls-secret
  rules:
  - host: localhost
    http:
      paths:
      - path: /(api/.*)
        backend:
          serviceName: service1
          servicePort: 80
      - path: /api2/(api.*)
        backend:
          serviceName: service2
          servicePort: 80
      - path: /api3/(api.*)
        backend:
          serviceName: service3
          servicePort: 80
      - path: /(.*)
        backend:
          serviceName: service4
          servicePort: 80
</code></pre>

<p>Just for context for anyone else stumbling upon this in the future, service 1 is a main API, service 2 and 3 are other APIs under another subdomain and service 4 is a web frontend.</p>
