<p>I'm working on a project where i need a front-end in angular and a back-end with spring-boot.
I've made 2 docker images for them, and used an ingress like the following to dipatch requests to the correct service:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: smf-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: rest-service
                port:
                  number: 80
          - path: /
            pathType: Prefix
            backend:
              service: 
                name: ng-service
                port:
                  number: 4200


</code></pre>
<p>As you see, all requests matching '/api*' are redirected to the rest-service, which is my spring boot application.</p>
<p>If i make a request, say '/api/helloworld', to the ingress, <strong>how is this request modified before reaching spring endpoints?</strong>
Will spring receive the same request, calling an endpoint mapped to '/api/helloworld' or not?</p>
<p>I'm asking this because I mapped my endpoints in spring to '/api/some_endpoint' , but every time i try to access those urls from the browser i get spring error page (404).
To achieve this behavior I set the following property in my spring boot application:</p>
<pre><code>server.servlet.context-path=/api
</code></pre>
<p>is this wrong? why? can you explain me a solution?</p>

Luca Pasini
<p>First some context, Kubernetes does not include an Ingress Controller so this all specific to ingress-nginx, which I assume you are running given the annotation you are asking about is specific to that project. Other Ingress Controllers will work differently.</p>
<p>That said, you can find the documentation for the rewrite feature here <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/#deployment" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/#deployment</a>. The rewrite is implemented in Nginx, more specifically the ingress-nginx controller takes all your Ingress objects and generates an nginx config file, which is then handed off to normal standard nginx as the proxy.</p>
<p>The behavior you have there will be equivalent to <code>s|^/api|/|</code>, however as noted in the docs the behavior changed in version 0.22 so if you're on a newer version that probably wouldn't work as you expect.</p>
