<p>I have issue with deploying angular app on minikube. I am not able to expose the running angular container on browser.</p>

<p>Below are my setup files.</p>

<h2>Minikube start command</h2>

<pre><code>$ minikube start --driver=docker
</code></pre>

<h2>Dockerfile</h2>

<pre><code>FROM node:10-alpine AS node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build-prod
FROM nginx:alpine
COPY --from=node /app/dist/shopping-wepapp /usr/share/nginx/html
</code></pre>

<h2>Deployment configuration file</h2>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: shop-cart
spec:
  replicas: 2
  selector:
    matchLabels:
      app: shop-cart
  template:
    metadata:
      labels:
        app: shop-cart
        version: v1
    spec:
      containers:
        - name: shop-cart
          image:  kavin1995/development:shop-cart-app-07-04-2020-14-00
          imagePullPolicy: Always
          ports:
            - containerPort: 80
</code></pre>

<h2>Service configuration file</h2>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: shop-cart-service
spec:
  selector:
    app: shop-cart
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 31000
  type: NodePort
</code></pre>

<h2>Port exposing command</h2>

<pre><code>$ minikube service shop-cart-service --url 
</code></pre>

Kavinkumar
<p>The problem seems to be the use of the <code>docker</code> driver: the minikube IP is a container IP and cannot be accessed outside of the docker host.</p>

<p>The only way to expose the nodePort outside would be to publish the port on the <strong>running</strong> minikube container (which only expose this: <code>127.0.0.1:32771-&gt;22/tcp, 127.0.0.1:32770-&gt;2376/tcp, 127.0.0.1:32769-&gt;5000/tcp, 127.0.0.1:32768-&gt;8443/tcp</code>)</p>

<p>One way to do this would be (even if ugly) :</p>

<pre class="lang-sh prettyprint-override"><code>CONTAINER_IP=`minikube ip`
SERVICE_NAME=shop-cart-service
SERVICE_NODE_PORT=`kubectl get service ${SERVICE_NAME} --output jsonpath='{.spec.ports[0].nodePort}'`

iptables -t nat -A DOCKER -p tcp --dport ${SERVICE_NODE_PORT} -j DNAT --to-destination ${CONTAINER_IP}:${SERVICE_NODE_PORT}
iptables -t nat -A POSTROUTING -j MASQUERADE -p tcp --source ${CONTAINER_IP} --destination ${CONTAINER_IP} --dport ${SERVICE_NODE_PORT}
iptables -A DOCKER -j ACCEPT -p tcp --destination ${CONTAINER_IP} --dport ${SERVICE_NODE_PORT}
</code></pre>
