如何解决入口,重写目标,前端和API相同的URL版本0.22.0 +
我想将这样的设置放在一起:
- example.com #frond end
- example.com/api
- example.com/authentication
很显然,它们中的每一个都是独立的应用程序,应该能够继续自己的路径ex. http://example.com/api/v1/test?v=ok
现在我有一个这样的Yaml:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: frontend-service
servicePort: 80
- path: /api(/|$)(.*)
backend:
serviceName: backend-service
servicePort: 80
- path: /authentication(/|$)(.*)
backend:
serviceName: identityserver-service
servicePort: 80
/ api和/ authentication按照我想要的方式运行,但是前端的子路径不起作用。因此,例如找不到 http://example.com/css/bootstrap.css
。
到目前为止,我已经尝试过
1-在前端路径的和处添加(/|$)(.*)
2-添加具有相同后缀以及端口和路径/.*
的前端路径的副本
他们都没有解决问题。
这是描述结果:
Name: test-ingress
Namespace: default
Address: 127.0.0.1
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
*
/ frontend-service:80 (10.1.80.38:80,10.1.80.43:80,10.1.80.50:80)
/api(/|$)(.*) backend-service:80 (10.1.80.39:80,10.1.80.42:80,10.1.80.47:80)
/authentication(/|$)(.*) identityserver-service:80 (10.1.80.40:80,10.1.80.41:80,10.1.80.45:80)
Annotations: nginx.ingress.kubernetes.io/rewrite-target: /$2
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal UPDATE 43s (x14 over 13h) nginx-ingress-controller Ingress default/test-ingress
PS:我发现一些答案似乎早于0.22.0版,并且在ex之前不再起作用。 kubernetes ingress with multiple target-rewrite
解决方法
您遇到的问题在于不正确的正则表达式。
如果启用了多行标志,则$
运算符将匹配字符串的末尾或行的末尾。在第一组中,您正在捕获/
或$
,但是您的字符串没有结束并且不匹配。
我对此进行了测试,并且可以使用此正则表达式:
paths:
- path: /()(.*)
backend:
serviceName: frontend-service
servicePort: 80
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。