<p>I have a simple application composed with Express.js as backend API and React.js as Frontend client.</p>

<p>I create a singles image container with frontend and backend
Application repo: <a href="https://github.com/vitorvr/list-users-kubernetes" rel="nofollow noreferrer">https://github.com/vitorvr/list-users-kubernetes</a></p>

<p>Dockerfile:</p>

<pre><code>FROM node:13

WORKDIR /usr/app/listusers

COPY . .

RUN yarn
RUN yarn client-install
RUN yarn client-build

EXPOSE 8080

CMD ["node", "server.js"]
</code></pre>

<p>server.js</p>

<pre><code>const express = require('express');
const cors = require('cors');
const path = require('path');

const app = express();
const ip = process.env.IP || '0.0.0.0';
const port = process.env.PORT || 8080;

app.use(express.json());
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));

app.get('/users', (req, res) =&gt; {
  res.json([
    { name: 'Jhon', id: 1 },
    { name: 'Ashe', id: 2 }
  ]);
});

app.listen(port, ip, () =&gt;
  console.log(`Server is running at http://${ip}:${port}`)
);
</code></pre>

<p>React call:</p>

<pre><code>const api = axios.create({
  baseURL: 'http://0.0.0.0:8080'
});

useEffect(() =&gt; {
  async function loadUsers() {
    const response = await api.get('/users');
    if (response.data) {
      setUsers(response.data);
    }
  }
  loadUsers();
}, []);
</code></pre>

<p>To deploy and run this image in minikube I use these follow commands:</p>

<pre><code>kubectl run list-users-kubernetes --image=list-users-kubernetes:1.0 --image-pull-policy=Never
kubectl expose pod list-users-kubernetes --type=LoadBalancer --port=8080
minikube service list-users-kubernetes
</code></pre>

<p>The issue occurs when the front end try to access the localhost:</p>

<p><a href="https://i.stack.imgur.com/jKTaq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jKTaq.png" alt="enter image description here"></a></p>

<p>I don't know where I need to fix this, if I have to do some fix in React, or do some settings in Kubernetes or even this is the best practice to deploy small applications as a Container Image at Kubernetes.</p>

<p>Thanks in advance.</p>

<p>Your Kubernetes node, assuming it is running as a virtual machine on your local development  machine, would have an IP address assigned to it. Similarly, when an IP address would be assigned to your pod where the "list-user-kubernetes" service is running. You can view the IP address by running the following command: <code>kubectl get pod list-users-kubernetes</code>, and to view more information add <code>-o wide</code> at the end of the command, eg. <code>kubectl get pod list-users-kubernetes -o wide</code>. </p>

<p>Alternatively, you can do port forwarding to your localhost using <code>kubectl port-forward pod/POD_NAME POD_PORT:LOCAL_PORT</code>. Example below:</p>

<p><code>kubectl port-forward pod/list-users-kubernetes 8080:8080</code> 
Note: You should run this as a background service or in a different tab in your terminal, as the port forwarding would be available as long as the command is running. </p>

<p>I would recommend using the second approach, as your external IP for the pod can change during deployments, but mapping it to localhost would allow you to run your app without making code changes. </p>

<p><a href="https://kubectl.docs.kubernetes.io/pages/container_debugging/port_forward_to_pods.html" rel="nofollow noreferrer">Link to port forwarding documentation</a></p>
