<p>I have a cluster Kubernetes cluster on a local machine and one raspberry pi. In order to test the cluster I created a nginx deployment and a service that I want to access as a NodePort. But for God know's why, I can't access said service. Bellow are my deployment and service files.</p>

<p><code>kubectl get nodes</code></p>

<pre><code>NAME      STATUS                        ROLES    AGE    VERSION
anima     Ready                         master   7d5h   v1.16.1
bahamut   Ready                         &lt;none&gt;   7d4h   v1.16.1

</code></pre>

<p>My service and deployment files:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
      nodeSelector:
        kubernetes.io/hostname: bahamut

</code></pre>

<pre><code>
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
  - port: 3030
    targetPort: 80
  type: NodePort

</code></pre>

<p>After <code>kubectl get pods -o wide</code>:</p>

<pre><code>NAME                     READY   STATUS    RESTARTS   AGE     IP            NODE      NOMINATED NODE   READINESS GATES
nginx-67c8c4b564-6x7g5   1/1     Running   0          6m21s   10.244.1.13   bahamut   &lt;none&gt;           &lt;none&gt;

</code></pre>

<p>My Deployments, <code>kubectl get deployments -o wide</code>:</p>

<pre><code>NAME    READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES         SELECTOR
nginx   1/1     1            1           7m55s   nginx        nginx:latest   app=nginx
</code></pre>

<p>My Services, <code>kubectl get svc -o wide</code>:</p>

<pre><code>NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE     SELECTOR
kubernetes   ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP          7d5h    &lt;none&gt;
nginx        NodePort    10.102.203.77   &lt;none&gt;        3030:30508/TCP   8m54s   app=nginx

</code></pre>

<p>And finally, <code>kubectl get endpoints -o wide</code>:</p>

<pre><code>NAME         ENDPOINTS           AGE
kubernetes   192.168.25.4:6443   7d5h
nginx        10.244.1.13:80      9m41s


</code></pre>

<p>My Kubernetes master local IP is <code>192.168.25.4</code> and my raspberry ip is <code>192.168.25.6</code>. After deploying the service I tried:</p>

<pre><code>curl 192.168.25.6:3030
curl: (7) Failed to connect to 192.168.25.6 port 3030: Connection refused

curl 192.168.25.6:80
curl: (7) Failed to connect to 192.168.25.6 port 80: Connection refused

curl 192.168.25.6:30508 (hangs)

</code></pre>

<p>Also tried using the master node IP, the Service IP and the listed Cluster IP, but nothing works.</p>

<p><strong>EDIT</strong></p>

<p>It works if I use <code>hostNetwork=true</code> on the deployment and access it using the node local IP on the container port, but obviously that's not what I want. I want to understand why Kubernetes isn't let me access the container through the service.</p>

<p>NodePort exposes the Service on each Node’s IP at a static port (the NodePort) in your case it is <code>30508</code>. Please see more details <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">here</a>. </p>

<p>And <a href="https://kubernetes.github.io/ingress-nginx/deploy/baremetal/" rel="nofollow noreferrer">this</a> will share more details on the bare-metal clusters.</p>
