P粉4594409912023-09-06 00:51:54
Environment variables in a Kubernetes Pod can be accessed in Node.js using process.env.
, similar to how they are accessed in any Node.js application. You're doing it the right way, so if the value is undefined, something might not be set correctly.
apiVersion: v1 kind: Pod metadata: name: secret-env-pod spec: containers: - name: mycontainer image: redis env: - name: SECRET_USERNAME valueFrom: secretKeyRef: name: mysecret key: username - name: SECRET_PASSWORD valueFrom: secretKeyRef: name: mysecret key: password
React Environment Variables: If you are trying to use environment variables in your React application, you need to prefix them with REACT_APP_
. Only environment variables starting with this prefix will be embedded in the build. Therefore, you will use process.env.REACT_APP_
to access them in your code.