<p>I am running kubernetes v1.16 under docker desktop for windows. I have installed the nginx-ingress controller v1.7.9 using helm. I have update my hosts file to have the following entry</p>
<p><code>127.0.0.1 application.local</code></p>
<p>I have a backend service named <code>hedgehog-service</code>.</p>
<p>The following ingress definition correctly forwards request to the backend.</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ml-zoo-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: application.local
    http:
      paths:
      - path: /hedgehog/
        backend:
          serviceName: hedgehog-service
          servicePort: 80
</code></pre>
<p><code>curl application.local/hedgehog</code> works as expected and hits the backend service.</p>
<p>However in order to correctly use the backend service I need to rewrite the target removing the url prefix <code>/hedgehog</code>. Hence I have the following ingress definition</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ml-zoo-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: application.local
    http:
      paths:
      - path: /hedgehog(/|$)(.*)
        backend:
          serviceName: hedgehog-service
          servicePort: 80
</code></pre>
<p>As indicated here: <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target</a></p>
<p>Now when I <code>curl application.local/hedgehog/test</code> the ingress controller does not communicate with the backend but according to the logs attempts to open a file</p>
<pre><code>2020/06/23 12:46:48 [error] 708#708: *792 open() &quot;/etc/nginx/html/hedgehog/test&quot; failed (2: No such file or directory), client: 192.168.65.3, server: application.local, request: &quot;GET /hedgehog/test HTTP/1.1&quot;, host: &quot;application.local&quot;
192.168.65.3 - - [23/Jun/2020:12:46:48 +0000] &quot;GET /hedgehog/test HTTP/1.1&quot; 404 153 &quot;-&quot; &quot;curl/7.65.3&quot; &quot;-&quot;
</code></pre>
<p>Here is the content of <code>etc/nginx/conf.d/default-ml-zoo-ingress</code></p>
<pre><code># configuration for default/ml-zoo-ingress

upstream default-ml-zoo-ingress-application.local-hedgehog-service-80 {
        zone default-ml-zoo-ingress-application.local-hedgehog-service-80 256k;
        random two least_conn;

        server 10.1.0.48:80 max_fails=1 fail_timeout=10s max_conns=0;
}

server {
        listen 80;
        server_tokens on;
        server_name application.local;

        location /hedgehog(/|$)(.*) {

                proxy_http_version 1.1;
                proxy_connect_timeout 60s;
                proxy_read_timeout 60s;
                proxy_send_timeout 60s;
                client_max_body_size 1m;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_buffering on;

                proxy_pass http://default-ml-zoo-ingress-application.local-hedgehog-service-80;

        }
}

</code></pre>
<p>Does anyone know why my URLs are not getting rewritten and the requsts delivered to the backend service?</p>
<p>Thanks in advance!</p>

Joe
<p>OK having played around with this for hours, once I had written the question my next google turned up an answer.</p>
<p>I installed nginx using helm with the following repo <code>stable/nginx-ingress</code>. However according to this issue <a href="https://github.com/kubernetes/ingress-nginx/issues/5756" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/issues/5756</a> that is in fact a legacy repository. I uninstalled my controller and changed the repository to <code>ingress-nginx</code></p>
<pre><code>helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
</code></pre>
<p>and everything appears to be working as expected. Still not sure why the previous controller installation failed but I can get back to work :)</p>
<blockquote>
<p>EDIT: For the aid of others that might end up here - in hindsight I am wondering if the reinstallation simply meant that I deleted and recreated my ingress which might have solved the original problem. In other words make sure you try recreating the ingress before reinstalling the ingress controller with helm.</p>
</blockquote>
