Home > front end >  Kubernetes ingress is giving me 404 if I don't use wildcard
Kubernetes ingress is giving me 404 if I don't use wildcard

Time:10-22

I am working on a microservice app and I use nginx ingress. I setup rules with 3 services, when I mention host in the rules like this bellow it always gives me 404 for all the services

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-srv
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
    cert-manager.io/issuer: "local-selfsigned"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - "tradephlo.local"
      secretName: tls-ca
  rules:
    - host: "tradephlo.local"
    - http:
        paths:
          - path: /api/main/?(.*)
            pathType: Prefix
            backend:
              service:
                name: tradephlo-main-srv
                port:
                  number: 4000
          - path: /api/integration/?(.*)
            pathType: Prefix
            backend:
              service:
                name: tradephlo-integration-srv
                port:
                  number: 5000
          - path: /?(.*)
            pathType: Prefix
            backend:
              service:
                name: tradephlo-client-srv
                port:
                  number: 3000

However if I put wildcard in the host under the rules it works perfectly

rules:
    - host: "*.tradephlo.local"

I don't want to generate wildcard SSL in the production. Please help me point out what I am doing wrong here.

CodePudding user response:

The problem is in dash - in the following line:

rules:
    - host: "tradephlo.local"
    - http:

Otherwise, it is 2 different hosts - tradephlo.local abd *.

We can check this with the following command:

kubectl describe ing ingress-srv

And we get this:

$ kubectl describe ing ingress-srv
Name:             ingress-srv
Namespace:        default
Address:          xxxxxxxxxx
Default backend:  default-http-backend:80 (10.60.0.9:8080)
TLS:
  tls-ca terminates tradephlo.local
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /api/main/?(.*)   nginx:80 (yyyyy:80)

And we get this after removed -:

$ kubectl describe ing ingress-srv
Name:             ingress-srv
Namespace:        default
Address:          xxxx
Default backend:  default-http-backend:80 (10.60.0.9:8080)
TLS:
  tls-ca terminates tradephlo.local
Rules:
  Host        Path  Backends
  ----        ----  --------
  tradephlo.local
              /api/main/?(.*)   nginx:80 (yyyyyy:80)

So there is no need to use wildcard, when you do this, ingress treats *.tradephlo.local as different host and proceeds to * rule.

  • Related