<p>Let's consider we have three environments:</p>

<ul>
<li><code>test.website.com</code></li>
<li><code>dev.website.com</code></li>
<li><code>prod.website.com</code></li>
</ul>

<p>Each of the environment consists of the following microservices: webapp, service1, service2. I want to be able to easily call all the services from JS frontend without having to deal with domains. It would be great if I could just call <code>/services/service1/</code> and the fact I am on the same domain would keep me in the same environment.</p>

<p>So let's consider dev environment:</p>

<ul>
<li><code>dev.website.com/</code> -> goes to webapp</li>
<li><code>dev.website.com/services/service1/</code> -> goes to service1</li>
<li><code>dev.website.com/services/service1/</code> ...</li>
</ul>

<p>To be able to do that, I configured ingress as follows:</p>

<pre><code>    - path: /services/service1/*
      backend:
        serviceName: service1
        servicePort: 8080
    - path: /services/service2/*
      backend:
        serviceName: service2
        servicePort: 8080
    - path: /*
      backend:
        serviceName: webapp
        servicePort: 8080
</code></pre>

<p>This would work great, but it doesn't.</p>

<ol>
<li>First issue is that the <code>service1</code> receives full path (<code>/services/service1</code>) instead of just <code>/</code> when being called. For that I found this: <code>ingress.kubernetes.io/rewrite-target: /</code> - But I also foudn that this feature is not implemented, which is contradictory and doesn't make much sense.</li>
<li>Second problem is that, the order of the services is not followed and call on <code>/services/service1/</code> ends up in <code>webapp</code>.</li>
</ol>

<p>Is this even a good approach? What is the best practice to do this?</p>

<p><strong>Edit</strong>:</p>

<p>According to suggestions I removed <code>*</code> from the path, which helped, but also removed necessary functionality. I need to be able to use:</p>

<ul>
<li><code>/en/</code> -> <code>webapp</code></li>
<li><code>/services/service1/method1</code> -> <code>service1</code></li>
</ul>

<p>This doesn't work without the <code>*</code> in path.</p>

Vojtěch
<ol>
<li><p>According to the <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md" rel="nofollow noreferrer">documentation of nginx-ingress</a>, the annotation prefix is now <code>nginx.ingress.kubernetes.io</code> and not <code>ingress.kubernetes.io</code> as you used. You can change it with the argument <code>--annotations-prefix</code>.</p></li>
<li><p>Try to remove the wildcard (<code>*</code>) from your <code>path</code>:</p></li>
</ol>

<pre><code>- path: /service/service1
  backend:
    serviceName: service1
    servicePort: 8080
- path: /service/service2
  backend:
    serviceName: service2
    servicePort: 8080
- path: /
  backend:
    serviceName: webapp
    servicePort: 8080
</code></pre>
