I have a create-react-app with default configurations. I have some PORT and APIs inside .env file configured with
REACT_APP_PORT=3000
and using inside app with process.env.REACT_APP_PORT.
I have my server deployed on Kubernetes. Can someone explain how to configure my create-react-app, to use environment variables provided by pods/containers?
I want to access cluster IP via Name given by kubectl svc
Update 1 :
I have the opposite scenario, I don't want my frontend env variables to be configured in kubernetes pod container, but want to use the pod's env variable
e.x CLUSTER_IP and CLUSTER_PORT with their name defined by pod's env variable inside my react app.
For eg.-
NAME TYPE CLUSTER-IP
XYZ ClusterIP x.y.z.a
and want to access XYZ in react app to point to the Cluster IP (x.y.z.a)
env
variableREACT_APP_PORT
is only used by the development script setup bycreate-react-app
. Nonetheless, here is the link to Kubernetes documentation on how to handle environment variables: kubernetes.io/docs/tasks/inject-data-application/… – guzmonnecreate-react-app
. Bare in mind that you won't be able to consume environment variables once the app is built. You will only be able to use them while you run your development server since it injects the environment variables values into React's code. – guzmonne