<p>I want to put my docker image running react into kubernetes and be able to hit the main page. I am able to get the main page just running <code>docker run --rm -p 3000:3000 reactdemo</code> locally. When I try to deploy to my kubernetes (running locally via docker-desktop) I get no response until eventually a timeout.</p>
<p>I tried this same process below with a springboot docker image and I am able to get a simple json response in my browser.</p>
<p>Below is my Dockerfile, deployment yaml (with service inside it), and commands I'm running to try and get my results. Morale is low, any help would be appreciated!</p>
<p>Dockerfile:</p>
<pre><code># pull official base image
FROM node

# set working directory
RUN mkdir /app
WORKDIR /app
# install app dependencies
COPY package.json /app
RUN npm install
# add app
COPY . /app

#Command to build ReactJS application for deploy might not need this...
RUN npm run build

# start app
CMD [&quot;npm&quot;, &quot;start&quot;]
</code></pre>
<p>Deployment file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo  
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
      - name: reactdemo
        image: reactdemo:latest
        imagePullPolicy: Never
        ports:
          - containerPort: 80             
---
apiVersion: v1
kind: Service
metadata:
  name: demo
spec:
  type: NodePort
  selector:
    app: demo
  ports:
    - port: 3000
      targetPort: 3000
      protocol: TCP
      nodePort: 31000
  selector:
    app: demo
</code></pre>
<p>I then open a port on my local machine to the nodeport for the service:</p>
<pre><code>PS C:\WINDOWS\system32&gt; kubectl port-forward pod/demo-854f4d78f6-qv4mt 31000:3000
Forwarding from 127.0.0.1:31000 -&gt; 3000
</code></pre>
<p>My assumption is that everything is in place at this point and I should be able to open a browser to hit <code>localhost:31000</code>. I expected to see that spinning react symbol for their landing page just like I do when I only run a local docker container.</p>
<p>Here is it all running:</p>
<pre><code>$ kubectl get all
NAME                        READY   STATUS    RESTARTS   AGE
pod/demo-854f4d78f6-7dn7c   1/1     Running   0          4s

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/demo         NodePort    10.111.203.209   &lt;none&gt;        3000:31000/TCP   4s
service/kubernetes   ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          9d

NAME                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/demo   1/1     1            1           4s

NAME                              DESIRED   CURRENT   READY   AGE
replicaset.apps/demo-854f4d78f6   1         1         1       4s
</code></pre>
<p>Some extra things to note:</p>
<ul>
<li>Although I don't have it setup currently I did have my springboot service in the deployment file. I logged into it's pod and ensured the react container was reachable. It was.</li>
<li>I haven't done anything with my firewall settings (but sort of assume I dont have to since the run with the springboot service worked?)</li>
<li>I see this in chrome developer tools and so far don't think it's related to my problem: crbug/1173575, non-JS module files deprecated. I see this response in the main browser page after some time:</li>
</ul>
<hr />
<pre><code>localhost didn’t send any data.
ERR_EMPTY_RESPONSE
</code></pre>

Damisco
<p>Thanks for all the feedback peeps! In trying out the solutions presented I found my error and it was pretty silly. I tried removing the service and trying the different port configs mentioned above. What solved it was using 127.0.0.1:31000 instead of localhost. Not sure why that fixed it but it did!</p>
<p>That being said a few comments I found while looking at the above comments.</p>
<ol>
<li>I found that I couldnt hit the cluster without doing the port forwarding regardless of whether I had a service defined or not.</li>
<li>ContainerPort to my understanding is for kubernetes to work on pod to pod communication and doesnt impact application function from a user perspective (could be wrong!)</li>
<li>good to know on minikube Im thinking about trying it out and if I do I'll know why port 3000 stops working.</li>
</ol>
<p>Thanks</p>
