<p>Hi i have a question when it comes to k8s and handling branches</p>

<p>my namespaces have the following :</p>

<ul>
<li>an API deployment</li>
<li>a <code>NodePort</code> service mapping the port <code>3000</code> of the deployment to port <code>80</code></li>
<li>a <code>postgres</code> instance to serve as a DB (Not important for this problem)</li>
<li>an <code>Ingress</code> exposing all</li>
</ul>

<p>I would like to find a way that would make it able to :</p>

<ul>
<li>When creating a new Branch, it makes my backend accessible to api.BRANCH_NAME.domain.com</li>
</ul>

<p>I'm not able to find any documentation helping, I've tried a lot of things so far but cannot make it work </p>

<p>Here's a repo to see what I have so far : <a href="https://github.com/girards/tracks" rel="nofollow noreferrer">https://github.com/girards/tracks</a></p>

<p>Thanks in advance</p>

<p>You could deploy an <a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/" rel="nofollow noreferrer">ingress controller</a> such as nginx and create <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">ingress resource</a> to expose backend services using <code>host</code>.</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: simple-ingress-example
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: api.branchname.domain.com
    http:
      paths:
      - path: /
        backend:
          serviceName: servicename
          servicePort: 3000
</code></pre>
