subdomain per branch/namespace on K8S

4/19/2020

Hi i have a question when it comes to k8s and handling branches

my namespaces have the following :

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

I would like to find a way that would make it able to :

  • When creating a new Branch, it makes my backend accessible to api.BRANCH_NAME.domain.com

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

Here's a repo to see what I have so far : https://github.com/girards/tracks

Thanks in advance

-- girard_s
branch
kubernetes
kubernetes-helm
kubernetes-ingress
subdomain

1 Answer

4/19/2020

You could deploy an ingress controller such as nginx and create ingress resource to expose backend services using host.

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
-- Arghya Sadhu
Source: StackOverflow