Traefik and URL redirects, how it can be done (K3S environment)?

89 views Asked by At

I have quite simple scenario: Ingress --> Service --> Pod with some Web service

What is needed:
somedomain.com/prefix1 --> Service1
somedomain.com/prefix2 --> Service2
somedomain.com/prefix3 --> Service3

It works for static pages only If Web service redirects to any other path, it does know about this /prefixN, I can see that browser is trying to reach /news, but Traefik does not know anything about this path and it fails.

---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: stripprefix
spec:
  stripPrefix:
    prefixes:
      - /speed
      - /nginx
      - /jenkins
...

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: services-ingress
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: default-stripprefix@kubernetescrd
spec:
  rules:
    - http:
        paths:
          - path: /speed
            pathType: Prefix
            backend:
              service:
                name: openspeedtest-service
                port:
                  number: 80
          - path: /nginx
            pathType: Prefix
            backend:
              service:
                name: nginx-service
                port:
                  number: 80
          - path: /jenkins
            pathType: Prefix
            backend:
              service:
                name: jenkins-service

Workaround for Jenkins: I can use option for Jenkins --prefix=/jenkins, but is is not the common solution for all Web resouces.

For example, lets take openspeedtest Pod/container. I can see openspeedtest page by /speed path, but once the Start button is pushed, Openspeedtest makes user go to /, but Ingress does now know anything about it and can't route traffic properly.

I belive this task should have a simple and robust solution, please advice.

1

There are 1 answers

0
Artem On

Answer on the question is to use host separation, not path seperation: How to display speedtester in kubernetes using ingress