GCP 中 kubernetes 内同一节点上从 Pod 到 Pod 的通信 [英] Communication from Pod to Pod on same node inside kubernetes in GCP

查看:30
本文介绍了GCP 中 kubernetes 内同一节点上从 Pod 到 Pod 的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为 kubernetes 中的前端(REACT)和后端(EXPRESS NODE JS)项目dockerized 并创建了部署和服务.我已经在谷歌云平台中成功部署在具有两个 Pod(即一个 Pod --> REACT APP 和第二个 POD --> EXPRESS NODE JS)的同一节点的 Kubernetes(单节点集群)中.

I have dockerized and created deployment and service for both front(REACT) and backend (EXPRESS NODE JS) project in kubernetes. I have successfully deployed in Kubernetes(Single node cluster) in Same Node with Two Pods(i.e One Pod --> REACT APP and SECOND POD --> EXPRESS NODE JS) in Google cloud Platform.

问题:

1.) 如何在 Kubernetes 集群的 Node 内从一个 Pod 到另一个 Pod 通信?

1.) How to communicate from one pod to another pod inside the Node in Kubernetes cluster?

2.) 我通过在 kubernetes 中创建 LoadBalancer 类型服务将我的 REACT 应用程序暴露给外部世界,并且我能够从浏览器访问 React App Endpoint.现在,是否可以从节点内的 REACT 应用程序访问 EXPRESS 应用程序,而无需将我的 EXPRESS 应用程序暴露给外部世界.如何实现这一目标?

2.) I have exposed my REACT app to the Outer world by creating LoadBalancer Type Service in kubernetes and i am able to access the React App Endpoint from the Browser. Now, Is it possible to access EXPRESS app from REACT app inside the node without exposing my EXPRESS app to outer world. How to achieve this?

提前致谢.

推荐答案

当前端是基于浏览器的 JavaScript 应用程序时,JavaScript 资源可能会从集群中的 Pod 托管,但逻辑不会在那里运行.前端 JavaScript 在用户的浏览器中运行.从用户的浏览器调用集群中的任何后端端点都需要在链中某处的外部 URL,而不仅仅是内部 URL.

When the frontend is a browser-based JavaScript app then the JavaScript resources may be hosted from a Pod in the cluster but the logic doesn't run there. The fronted JavaScript runs in the user's browser. Calling any backend endpoints in the cluster from the user's browser requires an external URL somewhere along the chain and not just an internal one.

执行此操作的典型方法是设置 LoadBalancer 类型的服务并将外部端点放入后端的配置中.另一种方法是设置一个 Ingress Controller 并将 Service 和 Ingress 与后端一起部署.使用 Ingress,您可以在部署服务之前知道外部 URL 是什么(如果您使用 DNS,这是最简单的).集群内部通信不需要 Ingress,可以使用 ClusterIP 类型的服务完成,但我认为您需要外部通信.

A typical way to do this is to set up a Service of type LoadBalancer and put the external endpoint into the backend's config. Another is to set up an Ingress Controller and deploy both Service and Ingress along with the backend. With Ingress you can know what the external URL will be before you deploy the Service (and this is easiest if you use DNS). Cluster-internal communication doesn't need Ingress and can be done with Services of type ClusterIP but I think you need external communication.

无论如何,您都需要公开一个外部入口点,以便用户访问 UI(JS 所在的位置).使用入口,您可以将到后端的路由配置为同一(外部)主机上的不同路径.

You will need to expose an external entry point for users to hit the UI anyway (the place where the JS is hosted). With ingress you could configure the route to the backend as a different path on the same (external) host.

这篇关于GCP 中 kubernetes 内同一节点上从 Pod 到 Pod 的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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