K3S Kubernetes Ingress with multiple web apps under same domain: getting 404

Viewed 363

Hi I am very new to kubernetes. I have a k3s.io cluster setup (Server version 1.20) and I want to run multiple web apps under the same domain. I use the k3s default ingress controller (traefik).

Depending on the path given, the request should be routed to the configured web app.

  • dev.xxxxxxx.de/app -> should go to my self developed .net blazor webassembly app

  • dev.xxxxxxx.de/graf -> should go to the grafana service/pod

Both apps/services are running in the browser and can be reached sucessfully by their service name via NodePort (without ingress). So I suspect the problem in ingress routing.

My ingress.yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  labels:
    environment: dev
  annotations:
    kubernetes.io/ingress.class: "traefik"
spec:
  tls:
  - hosts:
    - dev.xxxxxxx.de
      
  rules:
  - host: dev.xxxxxxx.de
    http:
      paths:
      - path: /app
        pathType: ImplementationSpecific
        backend:
          service:
            name: iot-app
            port: 
              number: 80
                
      - path: /graf
        pathType: ImplementationSpecific
        backend:
          service:
            name: grafana
            port: 
              number: 3000

The problem now is that when browsing to dev.xxxxxxx.de/app or dev.xxxxxxx.de/graf, in both cases the initial request is returned with a 200, but the subsequent requests like assets (css, js) return a 404.

enter image description here

I suspect that the URL

  • dev.xxxxx.de/app/bootstrap.min.css

is getting transformed to

  • dev.xxxxx.de/bootstrap.min.css

which leads to a 404.

All hints why I cannot fully browse both of the apps appreciated! Thanks.

1 Answers

As I solved the very same issue right now on my K3s-cluster:

Have you tried to start your master with the --cluster-domain option (see the docs)?

I added that option in the /etc/systemd/system/k3s.service of my master and that did the trick for me.

Related