<p>I'm trying to use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="noreferrer">NodePort</a> with <a href="https://kind.sigs.k8s.io/" rel="noreferrer">kind</a> but somehow it doesn't want to work.</p>

<p>I've successfully deployed the following cluster:</p>

<pre><code>apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 80
    hostPort: 30000
    listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
    protocol: tcp # Optional, defaults to tcp
- role: worker
</code></pre>

<p>and then a very simple deployment:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: hostname-deployment
  labels:
    app: hostname
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hostname
  template:
    metadata:
      labels:
        app: hostname
    spec:
      containers:
      - name: hostname
        image: hostname:0.1
        ports:
        - containerPort: 80
</code></pre>

<p>and a service:</p>

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

<p>and I can connect to the service via e.g.</p>

<pre><code>(in one terminal)
k port-forward service/hostname-service 8080:80
Forwarding from 127.0.0.1:8080 -&gt; 80

(another one)
curl localhost:8080
hostname: hostname-deployment-75c9fd6584-ddc59 at Wed, 17 Jun 2020 15:38:33 UTC
</code></pre>

<p>But I cannot connect to the service via the exposed NodePort</p>

<pre><code>curl -v localhost:30000
* Rebuilt URL to: localhost:30000/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 30000 (#0)
&gt; GET / HTTP/1.1
&gt; Host: localhost:30000
&gt; User-Agent: curl/7.58.0
&gt; Accept: */*
&gt;
* Recv failure: Connection reset by peer
* stopped the pause stream!
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
</code></pre>

<hr>

<p><code>kubectl get all</code> output:</p>

<pre><code>NAME                                       READY   STATUS    RESTARTS   AGE
pod/hostname-deployment-75c9fd6584-ddc59   1/1     Running   0          34m
pod/hostname-deployment-75c9fd6584-tg8db   1/1     Running   0          34m

NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/hostname-service   NodePort    10.107.104.231   &lt;none&gt;        80:30000/TCP   34m
service/kubernetes         ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP        35m

NAME                                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hostname-deployment   2/2     2            2           34m

NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/hostname-deployment-75c9fd6584   2         2         2       34m
</code></pre>

<p>Kind cluster configuration needs to be like below</p>
<pre><code>apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30000
    hostPort: 30000
    listenAddress: &quot;0.0.0.0&quot; # Optional, defaults to &quot;0.0.0.0&quot;
    protocol: tcp # Optional, defaults to tcp
- role: worker
</code></pre>
<p>This file is then passed to your creation command as <code>kind create cluster --config=config.yaml</code> (<a href="https://kind.sigs.k8s.io/docs/user/configuration/" rel="noreferrer">according to docs</a>).</p>
