<p><strong>Scenario:</strong></p>
<p>I have a k8s cluster with <code>host01</code>, <code>host02</code> and <code>host03</code>.</p>
<p>I'm running master on <code>host01</code> and slaves on <code>host02</code> and <code>host03</code>, and I want to open a port for client connections on master, ie I want to open: <code>host01:32702</code>.</p>
<p>Using following service.yaml, I managed to open <code>host01:32702</code>. To my surprise <code>host02:32702</code> and <code>host03:32702</code> are also open.</p>
<pre><code>kind: Service
# ...
spec:
  type: NodePort
  ports:
  - name: dashboard
    port: 8265
    targetPort: 8265
    nodePort: 32702
  selector:
    podonhost01: yes
</code></pre>
<p><strong>Questions:</strong></p>
<ul>
<li>Is this intended NodePort behavior? Is the selector not working?</li>
<li>If yes, then why is this the intended NodePort behavior? If I have 1000s hosts, then single service will open port 32702 on all these hosts?</li>
<li>How do I only open port 32702 on <code>host01</code> and not the rest of hosts?</li>
</ul>

<p>You can use the <strong>externalIP</strong>,</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app.kubernetes.io/name: MyApp
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 9376
  externalIPs:
    - HOST-01 IP
</code></pre>
<p>Ref : <a href="https://kubernetes.io/docs/concepts/services-networking/service/#external-ips" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#external-ips</a></p>
