Change Kubernetes docker-for-desktop cluster network ip Change Kubernetes docker-for-desktop cluster network ip kubernetes kubernetes

Change Kubernetes docker-for-desktop cluster network ip


Kubernetes also has a subnet that it uses and a corresponding network setting, which defaults to 10.1.0.0/16, but this setting is not exposed in the Docker for-win UI. In docker/for-win issue #1667: Can not access local network, with kubernetes installed, guillaumerose shows a workaround that I've altered a bit to read:

  1. Disable Kubernetes
  2. Restart Docker for-win to clicking on "Restart" from the "Troubleshoot" screen (the one with the bug icon) - this step is missing in guillaumerose's workaround, see below
  3. docker run -it --privileged --pid=host justincormack/nsenter1 and edit /var/lib/cni/conf/10-default.conflist. Change the mentioned 10.1.0.0/16 to the network you want. Don't forget the gateway and the dns
  4. Enable Kubernetes

In step 3, I changed /var/lib/cni/conf/10-default.conflist like this:

# diff -u 10-default.conflist.orig 10-default.conflist--- 10-default.conflist.orig+++ 10-default.conflist@@ -10,11 +10,11 @@       "hairpinMode": true,       "ipam": {         "type": "host-local",-        "subnet": "10.1.0.0/16",-        "gateway": "10.1.0.1"+        "subnet": "10.250.0.0/16",+        "gateway": "10.250.0.1"       },       "dns": {-        "nameservers": ["10.1.0.1"]+        "nameservers": ["10.250.0.1"]       }     },     {

And this works. I can now ping 10.1.119.43 and use kubernetes.

OBS! 10-default.conflist gets reset/reverted whenever docker is restarted

Yes, every time docker gets restarted (e.g. because of a windows reboot), kubernetes reverts back to using 10.1.0.0/16 and then it is broken again. Apply the workaround above once more, and it will work again.

So I personally have a ~/10-default.conflist.250 file with the above patch applied and then do:

docker run -i --rm --privileged --pid=host justincormack/nsenter1 /bin/sh -c '/bin/cat > /var/lib/cni/conf/10-default.conflist' < ~/10-default.conflist.250

as step 3 above instead of editing the file by hand over and over.

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 :-).

About the need to restart Docker for-win after disabling kubernetes

My experience is that when kubernetes has been restarted and has reverted to using 10.1.0.0/16, if I skip step 2 - the "restart Docker for-win" 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 10.1.0.0/16) but now I can follow the workaround again (including step 2). So restarting docker between disabling kubernetes and modifying 10-default.conflist makes the subsequent start of kubernetes actually work.

If anybody has any idea why the contents of /var/lib/cni/conf/10-default.conflist 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.


After spending time investigating my other answer, a colleague suggested:

Why bother with the kubernetes built-in to Docker for-win at all?

Why not just use "kind" - kubernetes-in-docker?

brew install kindkind create cluster# Cluster is ready for use:kubectl --context kind-kind get -A pods

Boom! Kubernetes running in 20 seconds. The entire one-node kubernetes cluster is running inside a single docker container. I don't think I'm ever going back...


Did you restart docker-for-desktop or your entire computer? And do you see those new network settings in the docker network adapter it should have created on your computer?If those network changes are not reflected on the virtual network adapter on your computer, then those changes somehow did not applied. Try uninstalling docker-for-desktop or the kubernetes service.

If that virtual network does have those changes, or maybe a second network adapter has been created on your computer for kubernetes, you might want to reinstall the kubernetes service. Kubernetes uses network specific configuration, which it got when installing the service.