<p>I have tested the app using minikube locally and it works. When I use the same Doeckerfile with deploymnt.yml, the pod returns to Error state with the below reason</p>

<p>Error: Cannot find module '/usr/src/app/server.js'</p>

<p>Dockerfile:</p>

<pre><code>FROM node:13-alpine
WORKDIR /api
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
</code></pre>

<p>Deployment.yml:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nodejs-app-dep
  labels:
    app: nodejs-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nodejs-app
  template:
    metadata:
      labels:
        app: nodejs-app
    spec:
      serviceAccountName: opp-sa
      imagePullSecrets:
        - name: xxx
      containers:
      - name: nodejs-app
        image: registry.xxxx.net/k8s_app
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
</code></pre>

<p>Assuming it could be a problem with "node_modules", I had "ls" on the WORDIR inside the Dockerfile and it does show me "node_modules". Does anyone what else to check to resolve this issue ?</p>

<p>@willrof, thanks for the detailed write-up. A reply to your response is limited to 30 characters and hence I'm posting as new comment.</p>

<p>My problem was resolved yesterday. It was with COPY . . </p>

<p>It works perfectly fine in my local but, when I tried to deploy onto the cluster with the same Dockerfile, I was running into the issue of "cannot find module..."</p>

<p>So it finally worked when the directory path was mentioned instead of . . while copying files</p>

<pre><code>COPY /api /usr/app         #copy project basically
WORKDIR /usr/app           #set workdir just before npm install
RUN npm install
EXPOSE 3000
</code></pre>

<p>Moving WORKDIR statement before installing "node_modules" worked in my case. I'm surprised to figure this as the problem though it worked locally with COPY . .</p>
