<p>Everytime I try to access a NodePort on my machine, it says &quot;Error Connection Refused.&quot; I don't understand since the examples I read online imply that I can run Docker Desktop on my laptop, connect to the cluster, and access services via their nodeport.</p>
<p>My machine:</p>
<ul>
<li>Windows 10</li>
<li>Docker Desktop (tested additionally with <code>k3s</code> and <code>minikube</code> with similar results)</li>
<li>Kubernetes 1.19+</li>
</ul>
<p>Kubernetes Configuration:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: ngnix-service
spec:
  selector:
    app: nginx
  type: NodePort
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30007
</code></pre>
<p>Output and cURL test:</p>
<pre><code>PS C:\Users\ME\nginx&gt; kubectl get svc
NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes      ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          169m
ngnix-service   NodePort    10.108.214.243   &lt;none&gt;        80:30007/TCP     7m19s

PS C:\Users\ME\nginx&gt; curl.exe http://localhost:30007
curl: (7) Failed to connect to localhost port 30007: Connection refused
</code></pre>
<p>I've also tried with the node ip:</p>
<pre><code>PS C:\Users\ME\nginx&gt; kubectl get nodes -o wide
NAME             STATUS   ROLES    AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE         KERNEL-VERSION     CONTAINER-RUNTIME
docker-desktop   Ready    master   6d    v1.19.7   192.168.65.4   &lt;none&gt;        Docker Desktop   5.10.25-linuxkit   docker://20.10.5

PS C:\Users\ME\nginx&gt; curl.exe http://192.168.65.4:30007
curl: (7) Failed to connect to 192.168.65.4 port 30007: Timed out
</code></pre>
<p>I get the same response when trying to access a NodePort from my browser (Chrome). <code>ERR_CONNECTION_REFUSED</code></p>
<p>Is there something I'm missing? Why are all NodePorts inaccessible?</p>

<p>Kubernetes run locally, still runs on its internal network.</p>
<blockquote>
<p>curl.exe <a href="http://192.168.65.4:30007" rel="nofollow noreferrer">http://192.168.65.4:30007</a></p>
</blockquote>
<p>Here you use an IP address that is internal Kubernetes network. You must expose your Kubernetes service so that it gets an cluster-external address.</p>
<p>See this part:</p>
<pre><code>EXTERNAL-IP
&lt;none&gt;
</code></pre>
<p>You typically expose the service outside the cluster with a Service of <code>type: Loadbalancer</code> or use an Ingress-gateway.</p>
<p>See this <a href="https://stackoverflow.com/a/50178697/213269">answer</a> on how you can change your Service from <code>type:NodePort</code> to <code>type: LoadBalancer</code> to expose it to your localhost.</p>
<p>The easiest way to access your service is to use <code>kubectl port-forward</code>, e.g.</p>
<pre><code>kubectl port-forward ngnix-service 8080:80
</code></pre>
<p>Then you can access it on <code>localhost:8080</code>.</p>
<p>See <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">Use Port Forwarding to Access Applications in a Cluster</a></p>
