B A.J Amar
B A.J Amar

Reputation: 143

Kubernetes Ingress Not Routing to Services in Different Namespaces

Problem:

I am trying to set up an Ingress resource in the default namespace that routes traffic to:

  1. Mongo Express (in the default namespace)
  2. Kubernetes Dashboard (which is in the kubernetes-dashboard namespace)

However, my Ingress is failing to find the kubernetes-dashboard service.


My Ingress Configuration (default namespace)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: main-ingress
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: apps.k8s
    http:
      paths:
      - path: /mongo-admin
        pathType: Prefix
        backend:
          service:
            name: mongo-express-service
            port:
              number: 80
      - path: /dashboard
        pathType: Prefix
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 80

Ingress Status (kubectl describe ingress main-ingress)

Rules:
  Host        Path            Backends
  ----        ----            --------
  apps.k8s    
              /mongo-admin    mongo-express-service:80 (working)
              /dashboard      kubernetes-dashboard:80 (<error: services "kubernetes-dashboard" not found>)

What I Have Tried:

  1. Checked if kubernetes-dashboard service exists

    kubectl get svc -n kubernetes-dashboard
    

    The service is running:

    NAME                   TYPE        CLUSTER-IP     PORT(S)   AGE
    kubernetes-dashboard   ClusterIP   10.96.234.56   443/TCP   30m
    
  2. Verified that Ingress is running

    kubectl get pods -n ingress-nginx
    
  3. Attempted to directly access the dashboard service using port-forwarding

    kubectl port-forward svc/kubernetes-dashboard -n kubernetes-dashboard 8443:443
    

    This works, but I want to use Ingress instead.


Question:

Since Ingress only works with services in the same namespace, how can I configure Ingress in the default namespace while routing to the kubernetes-dashboard service in kubernetes-dashboard namespace?

Is there a proper way to do this without moving the Ingress to kubernetes-dashboard?

Upvotes: 0

Views: 26

Answers (0)

Related Questions