<p>I my case, I have a branch wise deployment in EKS 1.14 and I want to handle this with "regex" &amp; Nginx ingress.</p>

<p>Scenario:- Let's say I have Branch B1 with service_A(apache service), Similarly under B2 with service_A((apache service) and so on and want to access the service via URL like:- apache-{branch_name}.example.com
Note :- Branch B1/B2 is nothing but unique namespaces where same kind of service is running.</p>

<p>I need single ingress from where I can control all different branch URL</p>

<p>My example file:-</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: regex-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  tls:
  - hosts:
    - '*.k8s.example.com'
    secretName: prod-crt
  rules:
  - host: {service_A-b1}.k8s.acko.in
    http:
      paths:
      - backend:
          serviceName: {service_A-b1} 
          servicePort: 80

  - host: {service_A-b2}.k8s.acko.in
    http:
      paths:
      - backend:
          serviceName: {service_A-b2}
          servicePort: 80



</code></pre>

<p>Nginx ingress don't work in this way, is not possible to have regex in <code>serviceName</code> neither <code>host</code>. </p>

<p>From NGINX <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/" rel="nofollow noreferrer">docs</a>:</p>

<blockquote>
  <p>Regular expressions and wild cards are not supported in the <code>spec.rules.host</code> field. Full hostnames must be used.</p>
</blockquote>

<p>You can use regex <strong>only</strong> in <code>path</code> field:</p>

<blockquote>
  <p>The ingress controller supports <strong>case insensitive</strong> regular expressions in the <code>spec.rules.http.paths.path</code> field. This can be enabled by setting the <code>nginx.ingress.kubernetes.io/use-regex</code> annotation to <code>true</code> (the default is false).</p>
</blockquote>

<p>If you need to control your <code>serviceName</code> and <code>host</code> dinamically I strong recommend use some kind of automation (could be jenkins, bash script etc...) or templates by <a href="https://helm.sh/" rel="nofollow noreferrer">HELM</a> which will modify at deployment time.</p>

<p><strong><em>References:</em></strong></p>

<p><a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/</a></p>
