Search code examples
kubernetesdevopstraefikk3s

Traefik returns 404 for subdirectory


I have this simple ingres config:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    traefik.ingress.kubernetes.io/router.tls: "true"
    traefik.ingress.kubernetes.io/router.middlewares: default-compress@kubernetescrd

spec:
  ingressClassName: traefik
  rules:
  - host: my-app.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app-public-service
            port:
              number: 80

      - path: /app
        pathType: Prefix
        backend:
          service:
            name: my-app-client-service
            port:
              number: 80

  - host: api.my-app.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app-server-service
            port:
              number: 80
  tls:
  - hosts:
    - my-app.com
    - api.my-app.com
    secretName: my-app-cert

For some reason, api.my-app.com and my-app.com works just fine, but my-app.com/app returns 404.

The service itself is working fine and can be accessed via curl by k8s service ip.

I was using nginx previously, this config worked absolutely fine.


Solution

  • For better community visibility posting the above comment as an answer.

    As suggested by @Lukman, to avoid the 404 error, ensure that the host path is my-app.com/app/.

    PathPrefix together with replacepath will select the service according to the PathPrefix and will serve the service from / instead of giving you 404s.

    Refer to the similar issue on Reddit community page for additional information.