Skip to content

Ingress sub-paths are not working in Kubernetes (K3S) #9998

@kevinmnm

Description

@kevinmnm

Welcome!

  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've searched similar issues on the Traefik community forum and didn't find any.

What did you do?

I'm using k3s. I'm trying to configure sub paths in ingress object but for some reason sub-paths are not working, instead they all shows the app pointed to index /. I've asked related question here if you also want to refer to it as well.

I have 3 working services:

$ kubectl get service

NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE    SELECTOR
theia-svc        ClusterIP   10.43.192.17    <none>        80/TCP     3h4m   app=theia-pod
hermes-svc       ClusterIP   10.43.218.245   <none>        8000/TCP   102m   app=hermes-pod
api-server-svc   ClusterIP   10.43.158.206   <none>        8082/TCP   102m   app=api-server-pod

The desired result is to see 3 different applications per path:

https://dev.mywebsite.io/                => theia-svc
https://dev.mywebsite.io/hermes          => hermes-svc
https://dev.mywebsite.io/api-server      => api-server-svc

What did you see instead?

Test 1: All sub-paths are showing app deployed at path "/"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/force-ssl-redirect: "false"
    ingress.kubernetes.io/ssl-redirect: "true"
    cert-manager.io/cluster-issuer: letsencrypt

  name: traefik-ingress
spec:
  ingressClassName: traefik
  rules:
    - host: dev.mywebsite.io
      http:
        paths:
          - path: /api-server # Not working, shows the 'theia-svc' app
            pathType: Prefix
            backend:
              service:
                name: api-server-svc
                port:
                  number: 8082
          - path: /hermes # Not working, shows the 'theia-svc' app
            pathType: Prefix
            backend:
              service:
                name: hermes-svc
                port:
                  number: 8000
          - path: / # Working, shows the 'theia-svc' app
            pathType: Prefix
            backend:
               service:
                  name: theia-svc
                  port:
                  number: 80
  tls:
    - hosts:
        - dev.mywebsite.io
      secretName: tls-secret

Test 2: Having just one sub-path does not work (404)

spec:
  ingressClassName: traefik
  rules:
    - host: dev.mywebsite.io
      http:
        paths:
          - path: /hermes # NOT working, 404
            pathType: Prefix
            backend:
              service:
                name: hermes-svc
                port:
                  number: 8000

Test 3: Having just one index path works

spec:
  ingressClassName: traefik
  rules:
    - host: dev.mywebsite.io
      http:
        paths:
          - path: / # Working, shows 'hermes-svc` app
            pathType: Prefix
            backend:
              service:
                name: hermes-svc
                port:
                  number: 8000

What version of Traefik are you using?

$ helm list --all-namespaces

NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                           APP VERSION
cert-manager    cert-manager    1               2023-06-30 18:32:00.115963257 +0000 UTC deployed        cert-manager-v1.12.2            v1.12.2
traefik         kube-system     1               2023-06-30 16:20:12.588390125 +0000 UTC deployed        traefik-21.2.1+up21.2.0         v2.9.10
traefik-crd     kube-system     1               2023-06-30 16:20:10.541179586 +0000 UTC deployed        traefik-crd-21.2.1+up21.2.0     v2.9.10

What is your environment & configuration?

Platform Info

$ lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy
$ k3s --version

k3s version v1.27.3+k3s1 (fe9604ca)
go version go1.20.5

Service Status

Service list:

$ kubectl get service -o wide

NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE     SELECTOR
kubernetes       ClusterIP   10.43.0.1       <none>        443/TCP    4h46m   <none>
theia-svc        ClusterIP   10.43.192.17    <none>        80/TCP     3h46m   app=theia-pod
hermes-svc       ClusterIP   10.43.218.245   <none>        8000/TCP   143m    app=hermes-pod
api-server-svc   ClusterIP   10.43.158.206   <none>        8082/TCP   143m    app=api-server-pod

theia-svc (port 80):

$ curl -I 10.43.192.17:80

HTTP/1.1 200 OK
Server: nginx/1.24.0
Date: Fri, 30 Jun 2023 21:07:13 GMT
Content-Type: text/html
Content-Length: 704
Last-Modified: Wed, 14 Jun 2023 22:54:49 GMT
Connection: keep-alive
ETag: "648a4539-2c0"
Accept-Ranges: bytes

hermes-svc (port 8000):

curl -I 10.43.218.245:8000

HTTP/1.1 200 OK
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Thu, 08 Jun 2023 21:26:10 GMT
ETag: W/"45c-1889ce71550"
Content-Type: text/html; charset=UTF-8
Content-Length: 1116
Date: Fri, 30 Jun 2023 21:07:28 GMT
Connection: keep-alive
Keep-Alive: timeout=5

api-server-svc (port 8082):

$ curl -I 10.43.158.206:8082

HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 13541
ETag: W/"34e5-CveslBbLOxvSX68sJoMVByvvMVk"
Date: Fri, 30 Jun 2023 21:07:39 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Traefik Ingress

k8.ingress-traefik.yml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/force-ssl-redirect: "false"
    ingress.kubernetes.io/ssl-redirect: "true"
    cert-manager.io/cluster-issuer: letsencrypt

  name: traefik-ingress
spec:
  ingressClassName: traefik
  rules:
    - host: dev.mywebsite.io
      http:
        paths:
          - path: /api-server
            pathType: Prefix
            backend:
              service:
                name: api-server-svc
                port:
                  number: 8082
          - path: /hermes 
            pathType: Prefix
            backend:
              service:
                name: hermes-svc
                port:
                  number: 8000
          - path: / 
            pathType: Prefix
            backend:
               service:
                  name: theia-svc
                  port:
                  number: 80
  tls:
    - hosts:
        - dev.mywebsite.io
      secretName: tls-secret

Cluster Issuer (letsencrypt)

k8.cluster-issuer.yml:

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: admin@email.com
    privateKeySecretRef:
      name: letsencrypt
    solvers:
      - http01:
          ingress:
            class: traefik
            podTemplate:
              spec:
                nodeSelector:
                  "kubernetes.io/os": linux

Services

k8.hermes.yml

apiVersion: "v1"

kind: "Service"

metadata:
  name: hermes-svc
spec:
  selector:
    app: hermes-pod
  type: "ClusterIP"
  ports:
  - port: 8000
    targetPort: 8000

k8.theia.yml:

apiVersion: "v1"

kind: "Service"

metadata:
  name: theia-svc
spec:
  selector:
    app: theia-pod
  # type: "NodePort"
  type: "ClusterIP"
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 80 

k8.api-server.yml:

apiVersion: "v1"

kind: "Service"

metadata:
  name: api-server-svc
spec:
  type: "ClusterIP"
  selector:
    app: api-server-pod
  ports:
    - port: 8082
      name: api-server-port
      targetPort: 8082

If applicable, please paste the log output in DEBUG level

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions