Kubernetes ingress-nginx call service from non-default namespace

2/15/2019

I have 3 services in my ingress, the first 2 use default namespace. The third service is prometheus-server service which has namespace ingress-nginx. Now, I want to map my prometheus DNS to the service, but getting error because ingress can't find the prometheus service in default namespace.

How to deal with non-default namespace in ingress definition?

-- Justinus Hermawan
docker
kubernetes
nginx-ingress
prometheus

2 Answers

2/15/2019

You will need to refer to your service in the other namespace with its full path, that is prometheus-server.ingress-nginx.svc.cluster.local.

You shouldn’t need a second Ingress to do this.

-- Paul Annetts
Source: StackOverflow

2/15/2019

You would want to create a new Ingress in namespace ingress-nginx that would route your DNS to that service. For example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example
  namespace: ingress-nginx
spec:
  rules:  
  - host: your.domain.com
    http:
      paths:
      - path: /
        backend:
          serviceName: prometheus-server
          servicePort: 80
-- Fei
Source: StackOverflow