<p>I have a Jenkins build process that deploys our code to several Kubernetes environments. Currently, it works fantastic with known/core branches (develop, release, master) and such, BUT we would like to make all of our feature branches and bug fix branches as well. In order to do this, we currently have it deploying an ingress with branch subdomains, like &quot;{branchName}.domain.tld&quot;. The problem here is that there is a proliferation of ingresses and such for each branch.</p>
<p>I would LIKE to do something like &quot;branch.domain.tld/{branchName}&quot; and have the ingress dynamically route based on the &quot;branchName&quot; path. Unfortunately I only seem to get a single ingress per subdomain/host assignment (branch.domain.tld/bugfix_nasty doesn't route because branch.domain.tld/feat_cool already is defined).</p>
<p>What I would like to see is a single ingress that looks something like this:</p>
<pre><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: dynamic_ingress
    annotations:
      {...stuff here}
  spec:
    rules:
    - host: branch.domain.tld
      http:
        paths:
        - path: /{branchName}/*
          backend:
            serviceName: {branchName}
            servicePort: 80
</code></pre>
<p>Is there anyway to get to such a zenlike ingress?</p>
<p>All the stuff I see about this type of thing is advice on using regex for the path to capture and route to a known, defined service. I want this to route to variable service names.</p>

<p>As far as I know Ingress objects don't allow what you're trying to do. But there could be a workaround if you can modify the Ingress object every time you deploy a new branch.<br />
Whenever a new branch is deployed update your &quot;dynamic_ingress&quot; to include an extra path for the new branch. This can be achieved using a small utility that can read and write YAMLs which can then be applied to update the existing Ingress OR you can use <code>kubectl patch</code> to update the existing Ingress at deploy time.<br />
This way the Ingress definition has static paths but neither do you have to set the paths manually nor do you need multiple Ingress objects.<br />
So you would have something like this.</p>
<pre><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: dynamic_ingress
    annotations:
      {...stuff here}
  spec:
    rules:
    - host: branch.domain.tld
      http:
        paths:
        - path: /bug_fix_nasty/
          pathType: Prefix
          backend:
            serviceName: bug_fix_nasty
            servicePort: 80
        - path: /feat_cool/
          pathType: Prefix
          backend:
            serviceName: feat_cool
            servicePort: 80
</code></pre>
<p>Check out all the examples in the <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress doc</a> and see which suits you best.</p>
