<p>I'm unable to specify an <code>Ingress</code> resource correctly so that an app's <code>Location</code> header is rewritten to include the original URL path in front.</p>
<p>Using config:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-fanout-namespace-xyz
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  namespace: namespace-xyz
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
          - path: /analytics/spark/master(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: spark-master-svc
                port:
                  number: 80
          - path: /analytics/jupyter/lab(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: jupyter-proxy-public
                port:
                  number: 80
</code></pre>
<p>Request URL: <a href="https://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/" rel="nofollow noreferrer">https://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/</a></p>
<p>Response header: <code>location: /hub/</code></p>
<p>Redirects to <a href="https://xx-xx.yyy.elb.amazonaws.com/hub/" rel="nofollow noreferrer">https://xx-xx.yyy.elb.amazonaws.com/hub/</a>, 404s.</p>
<p>This should instead send redirect for <code>location: /analytics/jupyter/lab/</code></p>
<p>This seems to be what <code>add-base-url</code> was for, which is now deprecated. <strong>What is the proper replacement and how can I effectively make the <code>Location</code> become <code>/analytics/jupyter/lab/hub/</code> ?</strong></p>
<hr />
<p>If I remove <code>rewrite-target</code> altogether, then <a href="http://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/" rel="nofollow noreferrer">http://xx-xx.yyy.elb.amazonaws.com/analytics/jupyter/lab/</a> does not redirect at all, it just 404s.</p>
<hr />
<p>Info:</p>
<p>NGINX Ingress controller version:</p>
<pre><code>-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       v1.0.5
  Build:         7ce96cbcf668f94a0d1ee0a674e96002948bff6f
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: nginx/1.19.9

-------------------------------------------------------------------------------
</code></pre>
<p>Kubernetes version (use <code>kubectl version</code>):</p>
<pre><code>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;21+&quot;, GitVersion:&quot;v1.21.2-13+d2965f0db10712&quot;, GitCommit:&quot;d2965f0db1071203c6f5bc662c2827c71fc8b20d&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-06-26T01:02:11Z&quot;, GoVersion:&quot;go1.16.5&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;21+&quot;, GitVersion:&quot;v1.21.2-eks-0389ca3&quot;, GitCommit:&quot;8a4e27b9d88142bbdd21b997b532eb6d493df6d2&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-07-31T01:34:46Z&quot;, GoVersion:&quot;go1.16.5&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>
<p>Environment:</p>
<ul>
<li>AWS EKS</li>
<li>Amazon Linux 2</li>
</ul>
<p>ingress-nginx-controller was installed thorugh ArgoCD / Helm with version info shown above and no values overridden.</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl describe ingressclasses
Name:         nginx
Labels:       app.kubernetes.io/component=controller
              app.kubernetes.io/instance=ingress-controller
              app.kubernetes.io/managed-by=Helm
              app.kubernetes.io/name=ingress-nginx
              app.kubernetes.io/version=1.0.5
              helm.sh/chart=ingress-nginx-4.0.9
Annotations:  &lt;none&gt;
Controller:   k8s.io/ingress-nginx
Events:       &lt;none&gt;
</code></pre>

Brad Solomon
<p><code>jupyter-proxy</code> needs its base_url to be set for the workload behind that service. Now it's unaware of the fact it is being served from a sub path, so when it send the redirect it sends as if it was (and actually is) served from the root url.</p>
<p>A quick test showed that</p>
<pre class="lang-sh prettyprint-override"><code>helm install my-jupyterhub jupyterhub/jupyterhub -n jupyterhub \
--create-namespace \
--set hub.baseUrl=&quot;/analytics/jupyter/lab&quot; \
--set ingress.enabled=true \
--set ingress.pathType=&quot;ImplementationSpecific&quot; \
--set proxy.service.type=NodePort \
--set ingress.annotations.'kubernetes\.io/ingress\.class'=nginx
</code></pre>
<p>deployed <code>jupyter hub</code> for me with <code>Ingress</code> and I was able to access it via <code>&lt;X.X.X.X&gt;/analytics/jupyter/lab/</code></p>
