<p>I am trying to configure Kubernetes on docker-for-desktops and I want to change the default network assigned to containers. </p>

<blockquote>
  <p>Example: the default network is <code>10.1.0.0/16</code> but I want <code>172.16.0.0/16</code>. </p>
</blockquote>

<p>I changed the docker network section to <code>Subnet address:  172.16.0.0 and netmask 255.255.0.0</code> but the cluster keeps assigning the network 10.1.0.0/16. 
<a href="https://i.stack.imgur.com/mdlFB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mdlFB.png" alt="Network configuration"></a></p>

<p>The problem I am facing here is that I am in a VPN which has the same network IP of kubernetes default network (<code>10.1.0.0/16</code>) so if I try to ping a host that is under the vpn, the container from which I am doing the ping keeps saying <code>Destination Host Unreachable</code>.</p>

<p>I am running Docker Desktop (under Windows Pro) Version 2.0.0.0-win81 (29211) Channel: stable Build: 4271b9e.</p>

<p>Kubernetes is provided from Docker desktop <a href="https://i.stack.imgur.com/xshra.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xshra.png" alt="Kuberbetes"></a></p>

<p>From the official <a href="https://docs.docker.com/docker-for-windows/kubernetes/" rel="noreferrer">documentation</a> I know that </p>

<blockquote>
  <p>Kubernetes is available in Docker for Windows 18.02 CE Edge and higher, and 18.06 Stable and higher , this includes a standalone Kubernetes server and client, as well as Docker CLI integration. The Kubernetes server runs locally within your Docker instance, <strong>is not configurable</strong>, and is a single-node cluster</p>
</blockquote>

<p>Said so, should Kubernetes  use the underlying docker's configuration (like network, volumes etc.)?</p>

<p>Kubernetes also has a subnet that it uses and a corresponding network setting, which defaults to <code>10.1.0.0/16</code>, but this setting is not exposed in the Docker for-win UI. In <a href="https://github.com/docker/for-win/issues/1667#issuecomment-367357067" rel="nofollow noreferrer">docker/for-win issue #1667: Can not access local network, with kubernetes installed</a>, guillaumerose shows a workaround that I've altered a bit to read:</p>
<ol>
<li>Disable Kubernetes</li>
<li>Restart Docker for-win to clicking on &quot;Restart&quot; from the &quot;Troubleshoot&quot; screen (the one with the bug icon) - this step is missing in guillaumerose's workaround, see below</li>
<li><code>docker run -it --privileged --pid=host justincormack/nsenter1</code> and edit <code>/var/lib/cni/conf/10-default.conflist</code>. Change the mentioned <code>10.1.0.0/16</code> to the network you want. Don't forget the gateway and the dns</li>
<li>Enable Kubernetes</li>
</ol>
<p>In step 3, I changed <code>/var/lib/cni/conf/10-default.conflist</code> like this:</p>
<pre><code># diff -u 10-default.conflist.orig 10-default.conflist
--- 10-default.conflist.orig
+++ 10-default.conflist
@@ -10,11 +10,11 @@
       &quot;hairpinMode&quot;: true,
       &quot;ipam&quot;: {
         &quot;type&quot;: &quot;host-local&quot;,
-        &quot;subnet&quot;: &quot;10.1.0.0/16&quot;,
-        &quot;gateway&quot;: &quot;10.1.0.1&quot;
+        &quot;subnet&quot;: &quot;10.250.0.0/16&quot;,
+        &quot;gateway&quot;: &quot;10.250.0.1&quot;
       },
       &quot;dns&quot;: {
-        &quot;nameservers&quot;: [&quot;10.1.0.1&quot;]
+        &quot;nameservers&quot;: [&quot;10.250.0.1&quot;]
       }
     },
     {
</code></pre>
<p>And this works. I can now ping <code>10.1.119.43</code> <em>and</em> use kubernetes.</p>
<h2>OBS! <code>10-default.conflist</code> gets reset/reverted whenever docker is restarted</h2>
<p>Yes, every time docker gets restarted (e.g. because of a windows reboot), kubernetes reverts back to using <code>10.1.0.0/16</code> and then it is broken again. Apply the workaround above once more, and it will work again.</p>
<p>So I personally have a <code>~/10-default.conflist.250</code> file with the above patch applied and then do:</p>
<pre><code>docker run -i --rm --privileged --pid=host justincormack/nsenter1 /bin/sh -c '/bin/cat &gt; /var/lib/cni/conf/10-default.conflist' &lt; ~/10-default.conflist.250
</code></pre>
<p>as step 3 above instead of editing the file by hand over and over.</p>
<p>It is quite annoying that this the workaround has to be applied every time docker for-win is restarted, but it is better than it not working :-).</p>
<h2>About the need to restart Docker for-win after disabling kubernetes</h2>
<p>My experience is that when kubernetes has been restarted and has reverted to using <code>10.1.0.0/16</code>, if I skip step 2 - the &quot;restart Docker for-win&quot; step - it takes more then 5 minutes to attempt to start kubernetes after which I give up waiting. When I now restart docker (because kubernetes is in a bad state), kubernetes will be re-enabled (again using <code>10.1.0.0/16</code>) but now I can follow the workaround again (including step 2). So restarting docker between disabling kubernetes and modifying <code>10-default.conflist</code> makes the subsequent start of kubernetes actually work.</p>
<p>If anybody has any idea why the contents of <code>/var/lib/cni/conf/10-default.conflist</code> revert to factory defaults every time docker gets restarted, I'm very curious to understand why that is and how to fix this last annoying problem.</p>
