title: How to redirect correctly usign nginx-ingress in Kubernetes
body: <p>I'm new to kubernetes and nginx, and am having trouble understanding how to implement Ingress (nginx-ingress) for my particular use case.</p>
  <p>I want to expose the pgadmin PostgreSQL admin tool from my cluster.</p>
  <p>I have other applications exposed via nginx-ingress from my cluster and I like each to hang off its own subdirectory e.g.:</p>
  <ul>
  <li>myserver.com/purchasing/index.html</li>
  <li>myserver.com/sales/index.html</li>
  </ul>
  <p>I have a problem doing this with pgadmin (although the problem would no doubt apply equally to other apps that behave in the same way)</p>
  <p>I have set up an Ingress rule to capture and route accordingly:</p>
  <pre><code>  annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/rewrite-target: /$2
  
    rules:
    - http:
        paths:
          - path: /pgadmin4(/|$)(.*)
  
  </code></pre>
  <p>it does the routing and the backend is hit.</p>
  <p>However when pgadmin then does a redirect, I lose the pgadmin/ from the redirect URl i.e.</p>
  <ul>
  <li>I send a GET to myserver.com/pgadmin</li>
  <li>I receive a 302 redirect to myserver.com/login</li>
  </ul>
  <p>whereas I want redirecting to:</p>
  <ul>
  <li>myserver.com/<strong>pgadmin</strong>/login</li>
  </ul>
  <p>What pieces am I missing to achieve this - it feels like it should be simple?</p>
  <p>Thanks</p>