kubernetes ingress with multiple target-rewrite

前端 未结 2 1926
野性不改
野性不改 2021-01-04 23:35

Usually ingress rewrite target works as follows:

nginx.ingress.kubernetes.io/rewrite-target: /

This will rewrite the target of your service

相关标签:
2条回答
  • 2021-01-05 00:31

    Another solution is create two ingress yaml files

    Each one using different annotations. It works!

    0 讨论(0)
  • 2021-01-05 00:38

    Unfortunately, Ingress based on free version of Nginx do not have that feature.

    But, if you can use Nginx Plus based Ingress, you can do it by annotation.

    Here is an example from official repo:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: cafe-ingress
      annotations:
        nginx.org/rewrites: "serviceName=tea-svc rewrite=/;serviceName=coffee-svc rewrite=/beans/"
    spec:
      rules:
      - host: cafe.example.com
        http:
          paths:
          - path: /tea/
            backend:
              serviceName: tea-svc
              servicePort: 80
          - path: /coffee/
            backend:
              serviceName: coffee-svc
              servicePort: 80
    

    Below are the examples of how the URI of requests to the tea-svc are rewritten (Note that the /tea requests are redirected to /tea/).

    /tea/ -> /
    /tea/abc -> /abc
    

    Below are the examples of how the URI of requests to the coffee-svc are rewritten (Note that the /coffee requests are redirected to /coffee/).

    /coffee/ -> /beans/
    /coffee/abc -> /beans/abc
    
    0 讨论(0)
提交回复
热议问题