<p>Is it possible in any way to redirect a hostpath to a subpath on the backend? Similar how <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer">subPaths</a> work for volumes.</p>

<p>The ingress would look like this:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: jupyter-notebook-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: jptrntbk.MYDOMAIN.com
      http:
        paths:
          - path: /
            backend:
              serviceName: jupyter-notebook-service
              servicePort: 8888
              subPath: /lab
</code></pre>

<p>Navigation to <code>jptrntbk.MYDOMAIN.com</code> would redirect to <code>/lab</code> on the backend and all other parentpaths are unavailable.</p>

Joost Döbken
<p>Create an Ingress rule with a app-root annotation:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/app-root: /app1
  name: approot
  namespace: default
spec:
  rules:
  - host: approot.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /
</code></pre>
<p>Check the rewrite is working</p>
<pre><code>$ curl -I -k http://approot.bar.com/
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.11.10
Date: Mon, 13 Mar 2017 14:57:15 GMT
Content-Type: text/html
Content-Length: 162
Location: http://approot.bar.com/app1
Connection: keep-alive
</code></pre>
<p>or can you create an Ingress rule with a rewrite annotation:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)
</code></pre>
<p>In this ingress definition, any characters captured by <code>(.*)</code> will be assigned to the placeholder <code>$2</code>, which is then used as a parameter in the <code>rewrite-target</code> annotation.</p>
<p>For example, the ingress definition above will result in the following rewrites: <code>- rewrite.bar.com/something</code> rewrites to <code>rewrite.bar.com/</code> - <code>rewrite.bar.com/something/</code> rewrites to <code>rewrite.bar.com/</code> - <code>rewrite.bar.com/something/new</code> rewrites to <code>rewrite.bar.com/new</code></p>
<p>Source: <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/rewrite/</a></p>
