将 Reactjs 应用程序连接到 Kubernetes 中的 Express Server 和 DocumentDB



我得到了一个React应用程序,该应用程序指向使用AWS DocumentDB进行持久性的Express服务。

在 React 应用程序的 src/config.js 文件中,我有以下内容:

module.exports = {
serverURL: 'http://localhost:5000'
};

在 Express 实例上,配置为:

module.exports = {
mongoConnectionString: 'mongodb://localhost/myappdb',
baseURL: 'http://localhost:5000',
port: 5000
};

我想将其部署在 Kubernetes 集群上,而 React 应用程序在与 Express 服务不同的 pod 上运行。当配置是 serverURL:"http://localhost:5000"时,如何告诉 React 应用程序向在 Kubernetes 中运行 Express 服务的 pod 发送请求?

如何在创建 kube pod 时更新 DocumentDB/mongodb 连接字符串?

另外,建议使用哪种方法?

用户 -> AWS ALB -> React 应用程序 -> Express 服务

用户 -> AWS ALB -> nginx -> React 应用程序 -> 快递服务

答案显然是使用变量。 :)

我的配置如下:

module.exports = {
serverURL: process.env.SERVER_HOST
};

环境变量和值存储在 Kubernetes 配置映射中:

kubectl create configmap backend-configmap --from-literal SERVER_HOST=$SERVER_HOST--namespace="backend" --dry-run -o yaml | kubectl apply -f -

简而言之,配置应该使用变量,变量应该作为配置映射添加到 Kubernetes 中。部署 (Pod( 引用这些配置映射。

最新更新