简体   繁体   English

在 kubernetes 上部署 2 层应用程序。 ClusterIP 和负载均衡器

[英]Deploying a 2 tier applicaton on kubernetes. ClusterIP & Loadbalancer

I have a backend API & Frontend application that i want to deploy on Kubernetes, all using docker images.我有一个后端 API 和前端应用程序,我想在 Kubernetes 上部署它,全部使用 docker 镜像。 I know how to deploy the Frontend using a Loadbalancer service & Ingress to expose the Frontend to the public internet.我知道如何使用 Loadbalancer 服务和 Ingress 部署前端以将前端公开到公共互联网。 The question i have is about how the backend API service will communicate with the frontend.我的问题是后端 API 服务将如何与前端通信。

I want to deploy the backend API using ClusterIP service, so it's only accessible to the Frontend from within the cluster, instead of exposing the backend API using ingress, hence, and no public access to the backend API我想使用 ClusterIP 服务部署后端 API,因此它只能从集群内被前端访问,而不是使用入口公开后端 API,因此,不能公开访问后端 API

Is this a good approach if i do decide to use Cluster IP?如果我决定使用集群 IP,这是一个好方法吗? & how will the Frontend be able to access the backend? &前端如何访问后端? will it be using http://localhost:4000 ?它会使用http://localhost:4000吗? or if an IP is generated it'll be fixed and it won't change?或者,如果生成了一个 IP,它将被修复并且不会改变? What's the best way to have an URL for the backend which the frontend can call获得前端可以调用的后端 URL 的最佳方法是什么

There are various options on connecting your frontend to backend and it all depends on your application architecture.将前端连接到后端有多种选择,这完全取决于您的应用程序架构。

You can expose your frontend using Ingress - it allows you to expose different parts of your app using different paths.您可以使用Ingress公开您的前端 - 它允许您使用不同的路径公开应用程序的不同部分。 And backend pods can be accessible only within cluster.后端 Pod 只能在集群内访问。 You can check "Connecting Applications with Services " in Kubernetes documentation.您可以在 Kubernetes 文档中查看“使用服务连接应用程序”

There are few examples available online that might help you decide how to approach it.在线提供的示例很少,可以帮助您决定如何处理它。

  1. You can take a look in official documentation: Connect a Front End to a Back End Using a Service .您可以查看官方文档: Connect a Front End to a Back End Using a Service

  2. There is a tutorial on how to connect frontend to backend using nginx有一个关于如何使用 nginx 将前端连接到后端的教程

  3. Similar question was also asked in SO, where good answer was given .在 SO 中也提出了类似的问题,其中给出了很好的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM