<p>We have a number of micro services in our eco system and a two of them deal with user data:</p>

<ul>
<li><p>user service -> </p>

<ul>
<li>POST /users</li>
<li>GET /users/[[:alnum:]]+</li>
</ul></li>
<li><p>documents service -> </p>

<ul>
<li>POST /users/[[:alnum:]]+/documents</li>
<li>GET /users/[[:alnum:]]+/documents/[[:alnum:]]+</li>
</ul></li>
</ul>

<p>Therefore I wanted to define this in an Ingress:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{.Release.Name}}
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    ingress.kubernetes.io/enable-cors: "false"
    ingress.kubernetes.io/ssl-redirect: "true"
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    app: "{{ template "fullname" . }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
    tier: frontend
spec:
  tls:
  - secretName: {{ template "tls.fullname" . }}
    hosts:
    - "staging.ourhost.com"
  rules:
  - host: "staging.ourhost.com"
    http:
      paths:
    - path: "/users/[[:alnum:]]+"
      backend:
        serviceName: {{ .Values.api.services.user_service  | quote }}
        servicePort: 8080
    - path: "/users/[[:alnum:]]+/documents"
      backend:
        serviceName: {{ .Values.api.services.document_service | quote }}
        servicePort: 8888
</code></pre>

<p>This results in the following being set in ngix.conf:</p>

<pre><code>location /users/[[:alnum:]]+ {
...
}

location /users/[[:alnum:]]+/documents{
...
}
</code></pre>

<p>i.e. the regex is not resolved.</p>

<p>I tried splitting it out into individual ingresses and using the annotation</p>

<pre><code>ingress.kubernetes.io/rewrite-target: "/users/$1/documents"
</code></pre>

<p>but this resulted in the following in nginx.conf</p>

<pre><code>location ~* ^/users/[[:alnum:]]+/documents/(?&lt;baseuri&gt;.*) {
            set $proxy_upstream_name "default-dev-document_service-8888";

  ...

    rewrite /users/[[:alnum:]]+/documents/(.*) /users/$1/documents/$1 break;
    proxy_pass http://default-dev-document_service-8888;

        }
</code></pre>

<p>Question (finally):</p>

<ul>
<li>Why is $1 always appended? this seems strange to me</li>
<li>Does someone know another way to make paths work with regex? </li>
</ul>

<p>Any advice would be greatly apreciated</p>

<p>After lots of searching, it seems that what I was trying to do is not (yet) possible in ingress. I opened a <a href="https://github.com/kubernetes/ingress-nginx/pull/1415" rel="nofollow noreferrer">PR</a> with them and I am waiting to see if it will be merged. </p>

<p>I have not yet publicly deployed a version with this change available, but the branch can be build using the dev docs from k8s</p>
