<p>I'm using kubernetes from docker for windows and I encountered problem. I use statefulset with following part of config:</p>
<pre><code>    spec:
      terminationGracePeriodSeconds: 300
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
</code></pre>
<p>In classic kubernetes this spec exposes all ports from pod on node ip, so all of them can be accessed through it. I'm trying to develop it on kubernetes from docker for windows, but it seems that I cannot access node by it's ip (like in minikube or microk8s), but docker for windows maps localhost to the cluster. So here is a problem:  this config exposes all ports on node ip, which is for example 192.168.65.4, but i cannot access it from windows - I can only access cluster via localhost, but it only exposes protocol related port, for example 443. So when my service runs on port i.e. 10433, there is no access from localhost:10433 but also there is no access in general through node ip. Is there any way to configure it to work as classic kubernetes, where all ports are exposed? I know that single port can be exposed through NodePort, but it's important for me to expose all ports from the pod to imitate real kubernetes behaviour</p>

MikolajMGT
<p>In general, <a href="https://docs.docker.com/network/host/" rel="nofollow noreferrer">Docker host networking</a> doesn't work on non-Linux platforms.  It's accepted as a valid Docker option, but the &quot;host&quot; network isn't actually the physical system's network.  This probably applies to the Kubernetes setup embedded in Docker Desktop as well.</p>
<p>It should be pretty rare to need host networking, and even more unusual in Kubernetes.  Host networking disables the normal inter-container communication mechanisms.  Kubernetes in particular has a <a href="https://kubernetes.io/docs/concepts/services-networking/" rel="nofollow noreferrer">complex network environment</a> and there is usually more than one node; opting out of the network setup like this can make it all but impossible to reach your service, either from inside the cluster or outside.</p>
<p>Instead of host networking, you should use the normal Kubernetes networking setup.  Pretty much every Deployment you create will need a matching <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Service</a>, and if you set that Service to have <code>type: nodePort</code> then it will be accessible from outside the cluster (try both the assigned <code>nodePort:</code> number and the service's cluster-internal <code>port:</code>; it's not clear <a href="https://stackoverflow.com/questions/50178696/access-a-kubernetes-service-running-locally-in-docker-for-desktop">which port Docker Desktop actually uses</a>).</p>
<p>For some purposes, the easiest approach is to set up a local port-forward to the service</p>
<pre class="lang-sh prettyprint-override"><code>kubectl port-forward deployment/some-deployment 8888:3000
</code></pre>
<p>will set up a port-forward from port 8888 on the local system to port 3000 on some pod managed by the named deployment.  This forwards to a <em>single</em> pod (if you have multiple replicas, it targets only one of them), it's slower than a direct connection, and the port-forward will fail occasionally, but this is good enough for maintenance tasks like database migrations.</p>
<blockquote>
<p>imitate real kubernetes behaviour</p>
</blockquote>
<p>In the environment I work on normally, each cluster has dozens to hundreds of nodes.  The nodes can't be directly accessed from outside the cluster.  It's also reasonably common to <a href="https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces" rel="nofollow noreferrer">configure a PodSecurityPolicy to disallow host networking</a> since it can be viewed as a security concern.</p>
