<p>I am trying to setup a sample React application wired to a NodeJS backend as two pods in Kubernetes. This is the (mostly) the <strong>default</strong> CRA and NodeJS application with Express i.e. <code>npx create-react-app my_app</code>.</p>

<p>Both application runs fine locally through <code>yarn start</code> and <code>npm app.js</code> respectively. The React application uses a proxy defined in <code>package.json</code> to communicate with the NodeJS back-end.</p>

<p><strong>React package.json</strong></p>

<pre><code>...
  "proxy": "http://localhost:3001/"
...
</code></pre>

<p><strong>React Dockerfile</strong></p>

<pre><code>FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN yarn
COPY . .
CMD [ "yarn", "start" ]
</code></pre>

<p><strong>NodeJS Dockerfile</strong></p>

<pre><code>FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3001
CMD [ "node", "app.js" ]
</code></pre>

<p><strong>ui-deployment</strong></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    name: sample-ui
    namespace: my_namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my_namespace
      component: sample-ui
  template:
    metadata:
      labels:
        app: my_namespace
        component: sample-ui
    spec:
      containers:
      - 
        name: sample-ui
        image: xxx
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
          name: http
          protocol: TCP
        resources:
          limits:
            cpu: 100m
            memory: 128Mi
          requests:
            cpu: 100m
            memory: 128Mi
</code></pre>

<p><strong>server-deployment</strong></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    name: sample-server
    namespace: my_namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my_namespace
      component: sample-server
  template:
    metadata:
      labels:
        app: my_namespace
        component: sample-server
    spec:
      containers:
      - 
        name: sample-server
        image: xxx
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3001
          name: http
          protocol: TCP
        resources:
          limits:
            cpu: 100m
            memory: 128Mi
          requests:
            cpu: 100m
            memory: 128Mi
</code></pre>

<p><strong>ui-service</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: sample-ui
  namespace: my_namespace
  labels: {app: sample-ui}
spec:
  type: LoadBalancer
  selector:
    component: sample-ui
  ports:
  - name: listen
    protocol: TCP
    port: 3000
</code></pre>

<p><strong>server-service</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: sample-server
  namespace: my_namespace
  labels: {app: sample-server}
spec:
  selector:
    component: sample-server
  ports:
  - name: listen
    protocol: TCP
    port: 3001
</code></pre>

<p>Both services run fine on my system.</p>

<p><strong>get svc</strong></p>

<pre><code>sample-server            ClusterIP      10.19.255.171   &lt;none&gt;           3001/TCP                     26m
sample-ui                LoadBalancer   10.19.242.42    34.82.235.125    3000:31074/TCP               26m
</code></pre>

<p>However, my deployment for the CRA crashes multiple time despite indicating it is still <code>running</code>.</p>

<p><strong>get pods</strong></p>

<pre><code>sample-server-598776c5fc-55jsz                     1/1     Running     0          42m
sample-ui-c75ccb746-qppk2                          1/1     Running     4          2m38s
</code></pre>

<p>I suspect that my <strong>React Dockerfile</strong> is improperly configured but I'm not sure how to write it to work with a NodeJS backend in kubernetes.</p>

<p><strong>a) How can I setup my Dockerfile for my CRA such that it will run in a pod?</strong></p>

<p><strong>b) How can I setup my docker services and pods such that they communicate?</strong></p>

Carrein
<p>You will have to use come API gateway in front of your server or you can use ambassador from kubernetes.</p>
<p>Then you can get your client connected to server.</p>
