如何在具有Ingress的K8中从Angular(Clusterip SVC)中调用Golang API(clusterip SVC)?
GO版本:1.17
ng版本:9
此项目由后端SVC和部署,前端SVC和部署, Ingress
后端服务:
service/fiber-service ClusterIP 10.105.244.88 <none> 3000/TCP 43m
入口文件:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-lite-srv
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: lite.com
http:
paths:
- path: /api/?(.*)
pathType: Prefix
backend:
service:
name: fiber-service
port:
number: 3000 # service port
- path: /?(.*) #need to check order
pathType: Prefix
backend:
service:
name: forms-service
port:
number: 80 # service port
当前我正在使用HTTPCLCLIENT,并且
testUrl(url: string): Observable<any> {
return this._http.get(url)
}
上面的代码 来自我的前端,并且在A上称为按钮单击事件
现在,隧道插图后,当我访问 http://lite.com 我可以通过请求 http://lite.com/api.com/api/v1
我要实现的是通过服务名称称呼后端API
例如:光纤服务:3000/api/v1 作为上述功能的URL
基本上是群集到群集服务而不涉及入口的
这是可能的还是入口干扰? 性能差异是什么? (因为这是一个内部交流)
go version: 1.17
ng version: 9
This project consists of a backend svc and deployment, frontend svc and deployment,
ingress
Backend service:
service/fiber-service ClusterIP 10.105.244.88 <none> 3000/TCP 43m
Ingress File:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-lite-srv
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: lite.com
http:
paths:
- path: /api/?(.*)
pathType: Prefix
backend:
service:
name: fiber-service
port:
number: 3000 # service port
- path: /?(.*) #need to check order
pathType: Prefix
backend:
service:
name: forms-service
port:
number: 80 # service port
Currently I am using HTTPClient and doing
testUrl(url: string): Observable<any> {
return this._http.get(url)
}
Above code is from my frontend and it is called on a button click event
Now, After tunnelling, I am able to access frontend when I visit http://lite.com
and I can make API calls by requesting on http://lite.com/api/v1 or something
What I am trying to achieve is call the backend API via service name
eg: fiber-service:3000/api/v1 as url to the above function
Basically clusterIP to clusterIP service without involving Ingress
Is this possible or does ingress interfere?
What will be the performance difference? (since this is an internal communication)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现不可能做到这一点,尤其是当一个人的前端具有客户端渲染时
,问题是当用户访问网页时,它会在客户端的系统上渲染。因此,我们无法找到
光纤服务:3000/api/v1
因此,必须通过Ingress IEhttp://lite> http://lite.com/api/v1
如果是服务器端渲染,则可以调用服务。
I found that it is not possible to do this especially when one's frontend has client side rendering
So, the problem is when user visits the webpage, it is rendered on the client's system. Hence, we are unable to find the
fiber-service:3000/api/v1
so, it has to be called via ingress i.e.http://lite.com/api/v1
If it was server side rendering, then it would have been possible to call the service.