I have been handed a React app which points to an Express service that uses AWS DocumentDB for persistence.
In the src/config.js file of the React app, I have the following:
module.exports = {
serverURL: 'http://localhost:5000'
};
On the Express instance, the configuration is:
module.exports = {
mongoConnectionString: 'mongodb://localhost/myappdb',
baseURL: 'http://localhost:5000',
port: 5000
};
I'd like to deploy this on a Kubernetes cluster with the React app running on separate pods from the Express service. How can I tell the React app to send requests to the pods running the Express service in Kubernetes when config is serverURL: ' http://localhost:5000 '?
How do I update the DocumentDB/mongodb connection string when kube pods are created?
Also, which approach is recommended?
user -> AWS ALB -> React app -> Express service
user -> AWS ALB -> nginx -> React app -> Express service
The answer is to use variables, obviously. :)
My configuration has the following:
module.exports = {
serverURL: process.env.SERVER_HOST
};
and the environment variable and value are stored in a Kubernetes configmap:
kubectl create configmap backend-configmap --from-literal SERVER_HOST=$SERVER_HOST--namespace="backend" --dry-run -o yaml | kubectl apply -f -
In short, configuration should use variables and variables should be added as configmaps in Kubernetes. The deployments (pods) reference these configmaps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.