Passing variable to npm app inside a container

5/20/2019

I've build a npm react-app that connects to a REST-backend using a given url. To run the app on kubernetes, I've distributed the app and put it into an nginx container. The app starts nicely, but I want to make the backend url configurable without having to rebuild the container image every time. I don't know how to do that or where to search for, any help would be appreciated

-- Urr4
docker
kubernetes
nginx
reactjs

2 Answers

5/20/2019

Ingress. If the react app and the rest backend are both hosted on kubernetes, I recommend using a relative path for the REST backend http://myurl for app, http://myurl/service for the backend. Then use ingress to map the /service path to the REST service. Your react app just points to /service and doesn't care about url you are hosting on.

-- frankd
Source: StackOverflow

5/21/2019

You have several methods to achieve your objective

    apiVersion: v1
    kind: Pod
    metadata:
     name: pod-name
    spec:
      containers:
      - name: envar-demo-container
        image: my_image:my_version
        env:
         - name: BACKEND_URL
           value: "http://my_backend_url"

Regards.

-- mdaguete
Source: StackOverflow