多个目标重写的kubernetes入口 [英] kubernetes ingress with multiple target-rewrite

查看:76
本文介绍了多个目标重写的kubernetes入口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,入口重写目标的工作方式如下:

Usually ingress rewrite target works as follows:

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

这将重写您的服务名称的目标,就像它们在根目录中一样.所以,如果我有这个:

This will rewrite the target of your service names as they are in the root directory. So if I have this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  tls:
  rules:
    http:
      paths:
      - path: /
        backend:
          serviceName: front-main
          servicePort: 80
      - path: /api
        backend:
          serviceName: back-main
          servicePort: 80

我的服务将像在/中一样接收数据.但是,我希望服务front-main发送根/,服务器back-main发送/someotherpath/.我该怎么办?

My services are going to receive data as they are in /. However, I would like for my service front-main to send root / and for the server back-main to send /someotherpath/. How can I do this?

是否有类似下一行的内容?

Is there something like the following line?

nginx.ingress.kubernetes.io/rewrite-target: "front-main: / ; back-main: /someotherpath"

我似乎在文档中找不到答案.

I don't seem to find the answer in the documentation.

推荐答案

不幸的是,基于Nginx的免费版本的Ingress没有该功能.

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

但是,如果您可以使用基于Nginx Plus的Ingress ,则可以通过注释来实现.

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

下面是如何重写对tea-svc的请求的URI的示例(请注意/tea请求将重定向到/tea/).

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

下面是如何重写对coffee-svc的请求的URI的示例(请注意,/coffee请求被重定向到/coffee/).

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

这篇关于多个目标重写的kubernetes入口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆