Home > Blockchain >  Ingress 404 Not Found When multiple hosts
Ingress 404 Not Found When multiple hosts

Time:01-24

I'm trying to setup an aks on Azure. I've got the pods running and an nginx ingress controller setup as per the documentation.

I have two services I want to run under two different subdomains. zoo.example.com, and circus.example.com. I have a ingress-controller.yaml file where I specify the hosts and config for the ingress controller.

With this yaml file, I am able to access the zoo service from zoo.example.com with no issue.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - zoo.example.com
      secretName: tls-secret
  rules:
    - host: zoo.example.com
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: zoo-ui
                port:
                  number: 80

However, when I try putting both zoo.example.com and circus.example.com in the same file I get a 404 not found when trying to access either domain.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service-2
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - zoo.example.com
        - circus.example.com
      secretName: tls-secret
  rules:
    - host: zoo.example.com
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: zoo-ui
                port:
                  number: 80
    - host: circus.example.com
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: circus-ui
                port:
                  number: 80

Any ideas on why this may be happening?

I've also tried putting both hosts into different ingress resources, however that makes it so that both zoo.example.com and circus.example.com point to the same ui service, which I am not sure of why that happens.

Appreciate any help.

CodePudding user response:

You have an extra hyphen - preceding the http, which makes it a separate item in the collection.

rules:
    - host: zoo.example.com
    - http:
        paths:

It must be part of the host item. Remove the -

rules:
    - host: zoo.example.com
      http:
        paths:
  • Related