<p>I have created the free IBM Cloud Kubernetes cluster and try to deploy my react pwa(created with create-react-app) in it from Docker image. I managed to deploy the app in the cluster, but my service worker doesn't work.</p>

<p>When I do <code>npm run build</code> and <code>serve -s build</code> everything in the app is working fine in localhost:5000.</p>

<p>But in the deployed app the serviceWorker is not found in the navigator and it never register the service worker:</p>

<pre><code>if (process.env.NODE_ENV === 'production' &amp;&amp; 'serviceWorker' in navigator) {
...
//never goes in here
registerValidSW(swUrl, config);
});
</code></pre>

<p>And also getting this error when trying to access caches in the deployed app:</p>

<pre><code>Uncaught (in promise) ReferenceError: caches is not defined
at c (runtime.js:45)
at Generator._invoke (runtime.js:264)
at Generator.O.forEach.e.&lt;computed&gt; [as next] (runtime.js:98)
at r (asyncToGenerator.js:3)
at l (asyncToGenerator.js:25)
at asyncToGenerator.js:32
at new Promise (&lt;anonymous&gt;)
at t.getRequests (asyncToGenerator.js:21)
at t.value (index.js:142)
</code></pre>

<p>My Dockerfile looks like this:</p>

<pre><code>FROM node:alpine as builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

FROM nginx
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html
</code></pre>

<p>And my deployment.yaml is looking like this:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-app-service
  labels:
    app: app
spec:
  type: NodePort
  ports:
  - port: 80
    name: http
  selector:
    app: app
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-app-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name: my-app
        image: us.icr.io/my-app-namespace/my-app
        ports:
        - containerPort: 8080
</code></pre>

MJICT
<ul>
<li><p>Which <code>node</code> and <code>npm</code> version do you have installed locally?</p>

<p>You set up in your <code>Dockerfile</code> the latest version of <code>node</code>:</p>

<p><code>FROM node:alpine as builder</code></p></li>
<li><p>Identify the version that you have locally running: 
<code>node --version</code></p>

<p>Now select the right version here <a href="https://hub.docker.com/_/node/?tab=tags" rel="nofollow noreferrer">Docker Hub node tags</a></p>

<p>Example: If your node version is <code>8</code>, you need set some version like:</p>

<p><code>FROM node:8-alpine</code></p></li>
</ul>
