netstat showing foreign ports as kubernetes:port. What does this mean?

That happens because of the way netstat renders output. It has nothing to do with actual Kubernetes.

I have Docker Desktop for Windows and it adds this to the hosts file:

# Added by Docker Desktop
192.168.43.196 host.docker.internal
192.168.43.196 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

There is a record which maps 127.0.0.1 to kubernetes.docker.internal. When netstat renders its output, it resolves foreign address and it looks at the hosts file and sees this record. It says kubernetes and that is what you see in the console. You can try to change it to

127.0.0.1 tomato.docker.internal

With this, netstat will print:

  Proto  Local Address          Foreign Address        State
  TCP    127.0.0.1:6940         tomato:6941            ESTABLISHED
  TCP    127.0.0.1:6941         tomato:6940            ESTABLISHED
  TCP    127.0.0.1:8080         tomato:40347           ESTABLISHED
  TCP    127.0.0.1:8080         tomato:40348           ESTABLISHED
  TCP    127.0.0.1:8080         tomato:40349           ESTABLISHED

So what actually happens is there are connections from localhost to localhost (netstat -b will show apps that create them). Nothing to do with Kubernetes.


It seems that Windows docker changed your hosts file. So, if you want to get rid of these connections, just comment out the corresponding lines in the hosts file.

The hosts file on Windows 10 is located in C:\Windows\System32\drivers\etc and the records may look something like 127.0.0.1 kubernetes.docker.internal. I am pretty sure it will disrupt your docker service on Windows (yet, I am not an expert), so don't forget to uncomment these lines whenever you need to get the docker service back.