<p>I am trying to setup a local cluster using minikube in a Windows machine. Following some tutorials in <code>kubernetes.io</code>, I got the following manifest for the cluster:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: external-nginx-deployment
  labels:
   app: external-nginx
spec: 
  selector: 
    matchLabels: 
      app: external-nginx
  replicas: 2 
  template: 
    metadata: 
      labels:
        app: external-nginx
    spec: 
      containers: 
      - name: external-nginx
        image: nginx 
        ports: 
        - containerPort: 80 
---
apiVersion: v1
kind: Service 
metadata: 
  name: expose-nginx 
  labels: 
   service: expose-nginx
spec: 
  type: NodePort 
  selector: 
    app: external-nginx 
  ports: 
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 32000
</code></pre>
<p>If I got things right, this should create a pod with a nginx instance and expose it to the host machine at port 32000.
However, when I run <code>curl http://$(minikube ip):32000</code>, I get a <strong>connection refused</strong> error.</p>
<p>I ran bash inside the service <em>expose-nginx</em> via <code>kubectl exec svc/expose-nginx -it bash</code> and from there I was able to access the <em>external-nginx</em> pods normally, which lead me to believe it is not a problem within the cluster.</p>
<p>I also tried to change the type of the service to LoadBalancer and enable the <code>minikube tunnel</code>, but got the same result.</p>
<p>Is there something I am missing?</p>

<p>Almost always by default <code>minikube</code> uses <code>docker</code> driver for the <code>minikube</code> VM creation. In the host system it looks like a big docker container for the VM in which other kubernetes components are run as containers as well. Based on tests <code>NodePort</code> for services often doesn't work as it's supposed to like accessing the service exposed via <code>NodePort</code> should work on <code>minikube_IP:NodePort</code> address.</p>
<p>Solutions are:</p>
<ul>
<li><p>for local testing use <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer"><code>kubectl port-forward</code></a> to expose service to the local machine (which OP did)</p>
</li>
<li><p>use <a href="https://minikube.sigs.k8s.io/docs/commands/service/" rel="nofollow noreferrer"><code>minikube service</code></a> command which will expose the service to the host machine. Works in a very similar way as <code>kubectl port-forward</code>.</p>
</li>
<li><p>instead of <code>docker</code> driver use proper virtual machine which will get its own IP address (<code>VirtualBox</code> or <code>hyperv</code> drivers - depends on the system). <a href="https://minikube.sigs.k8s.io/docs/drivers/" rel="nofollow noreferrer">Reference</a>.</p>
</li>
<li><p>(Not related to <code>minikube</code>) Use built-in feature <code>kubernetes</code> in Docker Desktop for Windows. I've already <a href="https://stackoverflow.com/a/69113528/15537201">tested it</a> and service type should be <code>LoadBalancer</code> - it will be exposed to the host machine on <code>localhost</code>.</p>
</li>
</ul>
