How to deploy multiple frontend application on same kubernetes cluster with only one hostname

11/6/2019

I've 3 angular applications that are deployed on Kubernetes. I'm trying to run all 3 with just one hostname and different paths. Here is my ingress.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  name: test-ingress-deployment
  namespace: my-namespace
spec:
  tls:
  - hosts:
    - dns-name.eastus.cloudapp.azure.com
    secretName: aks-ingress-tls
  rules:
  - host: dns-name.eastus.cloudapp.azure.com
    http:
      paths:
      - backend:
          serviceName: ui-svc
          servicePort: 80
        path: /(.*)
      - backend:
          serviceName: ui-svc-one
          servicePort: 80
        path: /one/?(.*)
      - backend:
          serviceName: ui-svc-two
          servicePort: 80
        path: /two/?(.*)

All these 3 services are in different namespaces. I'm getting 503 for every endpoint I'm trying to hit, after applying ingress.

-- Shiv Rajawat
azure-aks
kubernetes
kubernetes-ingress

1 Answer

11/6/2019

Documentation around this is scarce, at least I wasn't able to find something except for Github issues shedding a little light into this issue. But as far as I know cross namespace access was intentionally avoided in K8s, it would be a prime source of privilege escalation attacks.

To my knowledge you do have two options:

  1. You can run your ingress and ingress controller inside the kube-system namespace. But this is not recommended as kube-system is meant for K8s components only and it most likely creates security concerns.
  2. You can have the ingress in the namespace your service resides in. But then you need an ingress controller which allows merging of rules which not all support afaik.

There are probably more solutions out there, maybe someone with more in-depth K8s knowledge can shed more light on it.

-- yvesonline
Source: StackOverflow