我想通过一个入口公开各种服务。
rules:
- http:
paths:
# The path is the URL prefix for the service, e.g. /api/* or just /*
# Note that the service will receive the entire URL with the prefix
- path: /service1/*
backend:
serviceName: service1
servicePort: 5000
- path: /service2/*
backend:
serviceName: service2
servicePort: 5000
问题是包括前缀在内的整个URL都传递给了基础服务,因此所有请求都返回404错误:service1
和api在/service1/some/path
上不响应,而在/some/path
上直接响应
如何为基础服务指定前缀?
更新
我尝试如下使用重写目标。请求被发送到rasa-nlu
服务,但是它们都触发404,因为rasa-nlu
仍然获得/nlu
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /nlu
backend:
serviceName: rasa-nlu
servicePort: 5000
答案 0 :(得分:5)
这可能是您想要的;
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/rewrite-target: /
name: rewrite
namespace: default
spec:
rules:
- host: rewrite.bar.com
http:
paths:
- backend:
serviceName: echoheaders
servicePort: 80
path: /something
请注意注释以重写目标。
找到了这个here
答案 1 :(得分:0)
该线程可能直到现在都已解决,但仅出于解决之道。 下面将解决该问题,将其添加到重写注释中时,默认路径为/ nlu。 它来自nginx重写规则,该规则适用于location指令的定义。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
ingress.kubernetes.io/rewrite-target: /nlu
spec:
rules:
- http:
paths:
- path: /nlu
backend:
serviceName: rasa-nlu
servicePort: 5000