Search code examples
kubernetesnginxkubernetes-ingressnginx-ingress

Warning: Rejected - All hosts are taken by other resources


I'm trying to setup Nginx-ingress controller to manage two paths on the same hostname in bare metal based cluster.

In the app1 namespace i have below nginx resource:-

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app1-ingress
  namespace: app1
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app1
        pathType: Prefix
        backend:
          service:
            name: app1-service
            port:
              number: 80

And in the app2 namespace i have below nginx resource:-

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app2-ingress
  namespace: app2
spec:
  ingressClassName: nginx
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /app2
        pathType: Prefix
        backend:
          service:
            name: app2-service
            port:
              number: 80

My app1-service applied first and it is running fine, now when i applied the second app2-service it shows below warning and not able to access it on browser.

Annotations:       <none>
Events:
  Type     Reason    Age   From                      Message
  ----     ------    ----  ----                      -------
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources
  Warning  Rejected  54s   nginx-ingress-controller  All hosts are taken by other resources

How do i configure my nginx ingress resource to connect multiple service paths on the same hostname?


Solution

  • Default Nginx Ingress controller doesn't support having different Ingress resources with the same hostname. You can have one Ingress resource that contains multiple paths, but in this case all apps should live in one namespace. Like this:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: app1-ingress
      namespace: app1
    spec:
      ingressClassName: nginx
      rules:
      - host: web.example.com
        http:
          paths:
          - path: /app1
            pathType: Prefix
            backend:
              service:
                name: app1-service
                port:
                  number: 80
          - path: /app2
            pathType: Prefix
            backend:
              service:
                name: app2-service
                port:
                  number: 80
    

    Splitting ingresses between namespaces is currently not supported by standard Nginx Ingress controller.

    You may however take a look at an alternative implementation of Nginx Ingress by Nginx Inc. They have support for Mergeable Ingresses.