<p>I have a react app that I want to deploy to kubernetes using a docker file and host it using nginx. My Dockerfile looks like this</p>
<pre><code>FROM node:14-alpine as build

# Install git
RUN apk update &amp;&amp; apk upgrade &amp;&amp; \
    apk add --no-cache git

WORKDIR /src
COPY package*.json ./

RUN npm config set unsafe-perm true
RUN npm install
COPY . .
RUN npm run build
</code></pre>
<p>My kuberetes configuration after running kustomization looks like this</p>
<pre><code>apiVersion: v1
data:
  settings.ts.ctmpl: |
    export const LIGHTHOUSE_API_HOST = 'stageBackendURL';
kind: ConfigMap
metadata:
  name: lighthouse-web-configmap-6968hk6f5g
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: lighthouse-web
    manifest_type: svc
  name: lighthouse-web
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 3001
  selector:
    app: lighthouse-web
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: lighthouse-web
spec:
  minReadySeconds: 10
  progressDeadlineSeconds: 600
  selector:
    matchLabels:
      app: lighthouse-web
  template:
    metadata:
      labels:
        app: lighthouse-web
      name: lighthouse-web
    spec:
      containers:
      - args:
        - npm
        - run
        - serve
        image: &lt;url to image&gt;
        imagePullPolicy: Always
        name: lighthouse-web
        ports:
        - containerPort: 3001
          name: http
        volumeMounts:
        - mountPath: /src/src/settings.ts
          name: lighthouse-web-config
          subPath: settings.ts
        - mountPath: /src/build
          name: lighthouse-web-static
      - image: nginx:1.14
        imagePullPolicy: Always
        name: nginx
        ports:
        - containerPort: 80
          name: nginx
        volumeMounts:
        - mountPath: /usr/share/nginx/html
          name: lighthouse-web-static
      initContainers:
      - args:
        - -template
        - /config-templates/settings.ts.ctmpl:/config/settings.ts
        - -log-level
        - trace
        - -once
        image: &lt;URL TO DOCKER IMAGE&gt;
        imagePullPolicy: Always
        name: consul-template
        resources:
          limits:
            cpu: 500m
            memory: 500Mi
          requests:
            cpu: 500m
            memory: 500Mi
        volumeMounts:
        - mountPath: /config-templates
          name: lighthouse-web-configmap
        - mountPath: /config
          name: lighthouse-web-config
      volumes:
      - configMap:
          name: lighthouse-web-configmap-6968hk6f5g
        name: lighthouse-web-configmap
      - emptyDir: {}
        name: lighthouse-web-config
      - emptyDir: {}
        name: lighthouse-web-static
</code></pre>
<p>when i deploy this, the build directory is empty. I tried to ssh to the container and manually build it but got this error:</p>
<pre><code>export NODE_OPTIONS=--max_old_space_size=4096 &amp;&amp; react-scripts build

Creating an optimized production build...
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lighthouse@0.1.0 build: `export NODE_OPTIONS=--max_old_space_size=4096 &amp;&amp; react-scripts build`
npm ERR! Exit status 1
npm ERR!

</code></pre>
<p>I had earlier kept the memory and cpu at 1gi and 100m but tried increasing to 16Gi and 8Gi but still didn't work.</p>

Karan Sharma
<p>Few notes on the above :</p>
<p>1: I'd use multistage Dockerfile build, where your whole build process happens in the node container but the final, complete, built application is then copied into an nginx based container like</p>
<pre><code>FROM node as build
...
FROM nginx
COPY --from=build /path/to/app /usr/share/nginx/html
</code></pre>
<p>2: npm builds are expensive processes, doing npm build in your kube env, with reasonable runtime limits set, is very likely to run into issues like the one you mention here.</p>
<p>3: make sure that the app artifacts are correctly created on your workstation/build system</p>
