Search code examples
dockerkuberneteskubernetes-ingressnginx-ingressdocker-desktop

How to expose web application on Docker Desktop / Minikube


I deployed simple .NET Core application consisting of 3 pods using Docker Desktop with Kubernetes. My goals is to expose working web application in my host browser:

enter image description here

My React Application in Fronend pod points in appsettings.js file to Backend Cluster IP Service to fetch data from backend. When im inside the Frontend pod this works normally, fetch works.

Exposed Fronend Pod using NodePort Service, application is accessible but my problem is with failing requests to Backend pod - requests are pointing to Backend ClusterIP service and my host machine cannot resolve them.

How this should be done on single node environment like Docker Desktop or Minikube? It also should work if I would like to use multiple different backend apis in my frontend app.

Thanks for help!


Solution

  • In your case, both Frontend and Backend need to be accessible from outside the cluster. So the Backend service must be of type NodePort or LoadBalancer.

    The reason is that the Frontend does not interact with the Backend Service (in the cluster). The Frontend pod is just used by the browser to download your React application. Then the browser runs your React application. And this application - that does not run in your cluster - must consume the Backend Service. That is why the Backend Service must be externally accessible.