Search code examples
traefik

how to config traefik 2.2 forward url and remove keywords


I want to forward my request using treafik 2.2 and config my ingress like this:

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: soa-illidan-forward
  namespace: dabai-pro
  selfLink: /apis/extensions/v1beta1/namespaces/dabai-pro/ingresses/soa-illidan-forward
  uid: b0778435-4fff-4e78-b85f-a534833b73e0
  resourceVersion: '322554'
  generation: 1
  creationTimestamp: '2020-06-07T11:04:43Z'
spec:
  rules:
    - host: manage.example.net
      http:
        paths:
          - path: /service
            backend:
              serviceName: zuul-service
              servicePort: 8088
status:
  loadBalancer: {}

but the forward still using the key word service and forward to backend, how to remove the keywards service when forward request? I also tried this:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: pro-manage-route
  namespace: dabai-pro
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`manage.example.net`) 
      kind: Rule
      services:
        - name: be-illidan-frontend
          port: 80
    - match: Host(`manage.example.net`) && PathPrefix(`/service`)
      kind: Rule
      services:
        - name: zuul-service
          port: 8088

but still not work. and this is my request path:

https://manage.example.net/service/illidan/report/user/captcha

and I want forward to backend zuul-service's url is /illidan/report/user/captcha. not /service/illidan/report/user/captcha.


Solution

  • just using traefik StripPrefix middleware, for example:

    http:
      middlewares:
        test-stripprefix:
          stripPrefix:
            prefixes:
              - "/foobar"
              - "/fiibar"
    

    for more detail, read the traefik docs.