如何在具有Ingress的K8中从Angular(Clusterip SVC)中调用Golang API(clusterip SVC)?

发布于 2025-01-22 11:17:32 字数 1578 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2025-01-29 11:17:32

我发现不可能做到这一点,尤其是当一个人的前端具有客户端渲染

,问题是当用户访问网页时,它会在客户端的系统上渲染。因此,我们无法找到光纤服务:3000/api/v1因此,必须通过Ingress IE http://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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文